Chapter 9. PyUnit
PyUnit brings xUnit to Python. Python is an interpreted, interactive, object-oriented programming language, widely used for many different kinds of software development. Steve Purcell ported JUnit to Python to create PyUnit. It follows the generic xUnit model closely. The standard Python libraries have included PyUnit since Python 2.1.
Python is open source software that is copyrighted but freely usable and distributable. PyUnit has the same terms as Python itself, with a stipulation that Steve Purcell be credited as the author in the source code and any accompanying documentation.
For more information about Python, see http://www.python.org. PyUnit’s home is http://pyunit.sourceforge.net. The information in this chapter is based on Python 2.3.3, which includes Version 1.4.6 of PyUnit.
architecture is simple and effective. Tests are implemented by
inheritance from a base class,
supports test fixture behavior. Tests may be aggregated using a
. A number of
test assert methods are provided. The PyUnit module,
, not only contains the foundation code
for building unit tests, but also acts as a test runner to execute
tests from the command line. A GUI test runner is also provided.
Test classes are created by subclassing
TestCase. The simplest approach is to override the
shown in Example 9-1.
booktests.py """Unit test for book.py""" ...