Chapter 2. Does This Code Work? Doctests in Depth
In the first chapter, we learned how to run the sample tests created by manage.py startapp
. Although we used a Django utility to run the tests, there was nothing specific to Django about the sample tests themselves. In this chapter, we will start getting into details of how to write tests for a Django application. We will:
Begin writing the market research project created in the first chapter by developing some basic models that will be used by the project
Experiment with adding doctests to one of the models
Begin to learn the kinds of tests that are useful, and the kinds that just add clutter to the code
Discover some of the advantages and disadvantages of doctests
While the previous chapter mentioned both doctests and unit tests, the focus for this chapter will be on doctests exclusively. Developing unit tests for Django applications will be the focus of Chapter 3, Testing 1, 2, 3: Basic Unit Testing and Chapter 4, Getting Fancier: Django Unit...