O'Reilly logo

Programming Google App Engine by Dan Sanderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Django Unit Tests and Fixtures

The Django App Engine Helper includes support for unit tests using Django’s unit test runner and the App Engine development server. The unit test runner runs tests inside the development server’s environment, so tests can access the simulated services, including the simulated datastore. The test runner supports tests defined with the standard Python libraries unittest or doctest, or other test frameworks with test runner customizations. Django provides its own class for defining unittest test cases, called django.test.TestCase, which adds several Django-specific features.

For unittest tests, the runner looks in files in the Django application directory (e.g., bookstore/) named models.py and tests.py for classes that inherit from unittest.TestCase or django.test.TestCase. Each method of a test case class whose name begins with test is a separate test. For each test, the runner initializes the test environment, instantiates the TestCase class, and calls the method for the test. If the class defines a setUp() method, it calls it before each test. If the class defines a tearDown() method, it calls it after each test. You can use setUp() and tearDown() to create and clean up test data and preparation for every test in a test case.

The TestCase class provides methods that cause the test to report failure if the conditions tested are not met. self.assertEqual() takes two arguments, and causes the test to fail if the arguments are not equal. self.assert_() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required