• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Writing Unit Tests

The goal of writing unit tests is to convert your informal, manual, and interactive testing session into a formal test class. Python provides a module called unittest for this purpose; it is a port of the Java-based unit-testing product JUnit, by Kent Beck and Erich Gamma. There are three levels to the testing framework. (The following descriptions of the levels deviate a bit from the original definitions, as found in the Python library documentation at www.python.org/doc/current/lib/module-unittest.html.)

The smallest element of the unit test is a test, which is a single method in a TestCase class that tests the behavior of a small piece of code or a particular aspect of an implementation. A test case is a collection of tests that share the same setup/inputs. On top of all this sits the test suite, which is a collection of test cases and/or other test suites. Test suites combine tests that should be executed together. With the correct setup (as shown shortly in an example below), you can then execute test suites. For large projects such as Zope 3, it is useful to know that there is also the concept of a test runner, which manages the test run of all or a set of tests. Besides providing many testing options, the test runner also provides good feedback about the testing session.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint