My tests are seriously lacking and I don't have a whole lot of faith in them. What are some of the best practices for getting the most testing coverage I can using Django/Python? I've been taking a look at Freshen and Lettuce, which look pretty promising, but I can't use them for everything, can I? I'm looking for advice on how to structure my workflow/project with testing so that I can feel confident when deploying new code in a production environment.
Additionally this series of articles so far has some good advice on testing django apps: http://toastdriven.com/blog/2011/apr/10/guide-to-testing-in-django/ My only criticism of the answer would be to not store everything in the |
|||||||||||||
|
First, use the built-in Django testing. Write model tests as TestCase classes inside your models.py. Do that now. Before reading any further. Add I'll wait until you've finished that. Model tests complete? Good. Now create a tests.py file in each application. Every single one. All empty. In each tests.py file create Do it now. Create good and bad forms. Create forms with each individual field validation problem. Don't create all possible permutations of bad data. Just one test case for each individual validation rule. Do that now. Before reading any further. Add I'll wait until you've finished that. Now, you have to test each view function. They also go in the tests.py file. Each view function has at least two test cases, perhaps more, depending on the various decorators you're using. If a view function requires a login, you have two cases: logged in and not logged in. If a view function requires a permission, you have at least three cases: not logged in, logged in as the wrong user, logged in as the right user. For now, you just need to be sure that the view function did something and returns the correct HTML template with any piece of correct data. Don't go crazy. You just want to be sure all view functions actually return an expected page. Nothing more. Do that now. Before reading any further. Add I'll wait until you've finished that. Those are the tests you should write first before writing any application code. This will give you a testing baseline that confirms that your application will minimall sort-of run. One you have that finished, you can start to consider unit tests that reflect the real purpose and value behind your application. |
|||||||||||||||||||||
|
I'm assuming that you are done with Testing Django Applications. With the right set of helper tools you should be fine with the default unit testing using Django test framework. To get you started with measuring coverage you might want to look into coverage standalone to figure out what you have tested. Once installed, you can do something like this:
It will create
to get a full list on testing coverage (including code from other python libraries).
You can easily Also, I think there is a Now there are other tools like twill, etc. to address specific needs (like javascript testing). Also, if you want to go through the detailed baby steps of setting up vanilla testing under Django, you may want to read "Django 1.1 Testing and Debugging" (lookup on Amazon). |
|||
|