Table Of Contents

Test Driven Development

After you have created a TurboGears project with quickstart, you can start coding your web application right away, or, which is what we recommend, you can adopt a test driven development (TDD) style with TurboGears. What we describe here is completely optional, but it helps in creating structured, maintainable, and reliable software. You should also put the project code in a version control system, so that you can easily revert to an earlier stage should something go wrong.

The TDD Workflow

In test driven development you develop in small iteration cycles, which are carried out repeatedly, until all tests are passing. One iteration covers the following steps:

  1. Write a test.
  2. Run the test and see it fail (important!).
  3. Write stub code and make it compile (normally not needed with Python).
  4. Write the code to make the test pass.

If necessary:

  • Refactor the code.
  • Refactor the test (and elaborate).

Rinse and repeat...

Running Your Tests

After you create the quickstart project, you can start the test suite with the following command:

$ python test

This runs the nosetests tool, which will search your applications package directory and execute all test cases it finds which start with :doc:`/test`. When you create a new project, there will already be several test modules in the tests directory below your package directory, all named :doc:`/test`*.py. You can add more tests to these modules or add new test modules. See the nose documentation for information on how to write and name your test classes and functions.

More Information

This document showed you only the minimum you need to know to start with TDD. For more information on how to write tests for your TurboGears applications see the full Testing documentation.