February 2006
Intermediate to advanced
648 pages
14h 53m
English
The unittest module is used to perform unit testing. With unit testing, a developer writes a collection of isolated test cases for each element that makes up a program (for example, individual functions, methods, classes, and modules). These tests are then run to verify correct behavior. As programs grow in size, unit tests for various components can be combined to create large testing frameworks and testing tools. This can greatly simplify the task of verifying correct behavior as well isolating and fixing problems when they do occur. Use of the module is best illustrated by an example. For instance, suppose you had the following Python module:
# module: gcd.py def gcd(x,y): if not (isinstance(x,(int,long)) and isinstance(y,(int,long))): ...
Read now
Unlock full access