This projects is now a part of Django test utils. The 0.2 release is available at Pypi
Django testmaker is an application that writes tests for your Django views for you. You simply run a special development server, and it records tests for your application into your project for you. Tests will be in a Unit Test format, and it will create a separate test for each view that you hit.
Step 1:
Add test_utils to your INSTALLED_APPS settings.
Step 2:
./manage.py testmaker APP
This will start the development server with testmaker loaded in. APP must be in installed apps, and it will use Django's mechanism for finding it. It should look a little something like this:
eric@Odin:~/EH$ ./manage.py testmaker mine
Handling app 'mine'
Logging tests to /home/eric/Python/EH/mine/tests/mine_testmaker.py
Appending to current log file
Inserting TestMaker logging server...
Validating models...
0 errors found
Django version 1.0.1 final, using settings 'EH.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Then, as you browse around your site it will create unit test files for you, outputting the context variables and status code for each view that you visit. The test file used is in APP/tests/APP_testmaker.py. Once you have your tests written, you simply have to add them into your __init__.py, and then run your tests.
Step 3:
./manage.py test APP
This fixes a lot of complaints that people had about previous versions of test maker. This allows you to test apps that are anywhere on your Python Path (and in your INSTALLED_APPS), which makes life a lot easier. Each view also has it's own test name, which is a slugified version of the request path and the time when you hit it (because I needed something unique :)) You also may notice that there is rudimentary support for template tags; this will be explained upon in my next post. However, for now know that it only works for template tags that don't set a context variable, or use the format as <context_var> to set one.
If you pass the -f option to testmaker, it will create fixtures for you. They will be saved in APP/fixtures/APP_fixtures.FORMAT. The default format is XML because I was having problems with JSON.
Pass this in with a valid serialization format for Django. Options are currently json, yaml, or xml.
This allows you to pass in the normal address and post options for runserver.
I plan on having an option that allows you to restrict the views to the app that you passed in on the command line. This would inspect the URLConf for the app, and only output tests matching those URLs. This would allow you to fine tune your tests so that it is guaranteed to only test views in the app.
The current way of naming tests is a bit hackish, and could be improved. It works for now, and keeps names unique, so it's achieving that goal. Suggestions welcome for a better way to name things.
It is a total hack at current, but it works. Certainly a first, rough draft.
Enable setup.py test in your Django apps
4 days, 1 hour Ago (Comments: 1)
Migrating Django Test Fixtures Using South
3 weeks, 1 day Ago (Comments: 4)
A playground for Django Template tags and filters
1 month, 1 week Ago (Comments: 4)
EuroDjangoCon Talk: Testing Django
1 month, 4 weeks Ago (Comments: 10)
Django's Summer of Code students announced!
2 months, 2 weeks Ago (Comments: 0)
I may not have gone where I intended to go, but I think I have ended up where I intended to be.
- Douglas Adams

