Testing and checking: Testing.
Posted: 16/10/2011 Filed under: django, python, software development, testing Leave a comment »In a previous post I wrote about checking (or static testing) of code.
This post addresses the testing of p3docs.
Developing web applications in python is a pleasure because there are so many tools available, similarly testing in django is also a pleasure because it takes and builds upon standard python testing libraries.
Unit Testing
Choices
At the start there are two real choices in python unit testing; doctest or unittest.
I am not sure why but doctests always seem a little disorganised for me. I have seen them used successfully in the real world and even used them in smaller scripts but unittest is the direction chosen for p3docs.
I find them easier to maintain and I also find it useful to have a good separation between the test code and the module code, it stops me from ‘peeking’ at the code and swaying my decisions on the test code – mental blackboxing.
Getting nosey
Nose is a great way to extend unittest as projects grow, it offers several extra tricks and a few shortcuts, in my opinion it is hard to go back once you have used it.
Django testing
Django has great support for testing out of the box,but in my experience it quickly starts to fall short as projects get larger.
I already noted how much I like Nose and it is simple to integrate nose with django thanks to django-nose. After a very short setup you can run nosetests inside or outside django.
Load Testing
Whilst p3docs is never intended to have extremely heavy loads it is always good to be aware of its’ capacity. I recently met with a friend who suffered an accidental javascript DOS attack on his servers and had to restrict and scale accordingly. The most interesting thing for me was how this company did not have even a basic baseline for the load they could handle. If you don’t know where you are today how can you plan for tomorrow?
P3docs does not need the complexity of a fine tool like Mechanize due to the niche market it is in at the current moment, so a great benchmarking tool is pylot.
Using this you can get a feel for how much load the default configuration can take and create a baseline for improvement.