Tuesday, 8 July 2008

Google App Engine with Django Unit Testing

To my surprise it is extremely easy to develop unit tests for GAE apps. With the help of GoogleAppEngineDjangoHelper, you can write unit tests around your models and application logic against a fake backend store. So you should be able to test most of your code without involving a browser! Here is an list of steps to develop a doctest for GAE apps.
  1. Checkout http://code.google.com/p/google-app-engine-django/ and make the necessary changes to your code base according to http://code.google.com/p/google-app-engine-django/source/browse/trunk/README
  2. In your project directory run: python manage.py shell
  3. Explore the APIs and play with your models in the interactive session.
  4. Record the session as a doctest. See an example in the Rietveld project : http://code.google.com/p/rietveld/source/browse/branches/testing/codereview/tests.py
  5. Replay the test by: python manage.py test _your_pacakge_
(Sure you can write the more traditional unit tests as well after step 1, this is just an example to show how natural it is to write a unit test for GAE apps)

No comments: