« Django Aggregator v2 now has tagging, and you should too. | The value of conventions, aka testmaker for template tags. »
About a week ago, I went ahead and re-wrote testmaker and moved it into my django-test-utils project on github. The syntax is now a bit different, and the whole thing is much improved. This is version 0.2. The screencast from the last release still shows the gist of the project, except for the changed syntax.
Also note that my projects have permanent pages for documentation over at my projects page. This will stay up to date with the most current version of the software, and basically be a copy of this post for now.
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 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.
Posted at 11:41 p.m. on November 26, 2008
Comments: 4
Tags: django , post-a-day , project , testmaker
Announcing Django Crawler and django-test-utils
A start to the uber community
The value of conventions, aka testmaker for template tags.
Welcome to the home of Eric Holscher on the web. I talk about software development, mostly in the realm of Django. I am interested in the real time web, testing, mobile apps, and other things.
Why Read the Docs matters
1 week, 5 days ago (Comments: 7)
Read the Docs Update
9 months, 4 weeks ago (Comments: 2)
Using Reviewboard with Git
1 year ago (Comments: 0)
Read the Docs Updates
1 year ago (Comments: 1)
Handling Django Settings Files
1 year ago (Comments: 12)
Required Reading
1 year, 2 months ago (Comments: 0)
Using Haystack to index non-database content
1 year, 2 months ago (Comments: 4)
Correct commands to check out and update VCS repos
1 year, 2 months ago (Comments: 0)
Site upgrades
1 year, 2 months ago (Comments: 0)
Building a Django App Server with Chef: Part 4
1 year, 2 months ago (Comments: 1)
Setting up Django and mod_wsgi
Building a Django App Server with Chef: Part 1
Screencast: Django Command Extensions
Big list of Django tips (and some python tips too)
Handling Django Settings Files
Lessons Learned From The Dash: Easy Django Deployment
Large Problems in Django, Mostly Solved: Delayed Execution
Building a Django App Server with Chef: Part 2


Comments
1 Eric Florenzano says...
Cool! By the way, in your eyes, do you see testmaker as a tool to create regression tests, or more as a tool to create the scaffolding for what you should manually craft into more targeted tests?
Posted at 6:52 a.m. on November 27, 2008
2 Eugene Pyvovarov says...
Thanks for great posts about testing and for great testing tools! Will check this out today :)
Posted at 12:08 p.m. on November 27, 2008
3 timc3 says...
Do you have any more examples on getting this to run? I couldn't get django to run the tests that got created.
I even tried to rename the file to tests.py and put it in the application directory but to no avail.
Posted at 9:02 p.m. on December 4, 2008
4 pterk says...
@timc3: Did you also remove the tests dir?
Posted at 11:10 p.m. on December 7, 2008