-
Book Overview & Buying
-
Table Of Contents
Mastering IPython 4.0
By :
unittest is the built-in (since version 2.1) testing framework for Python. It is modelled after the excellent JUnit framework for Java, and the xUnit testing frameworks in general. This makes for a clean, object-oriented style.
unittest supports the standard unit testing parts in a straightforward manner. The following concepts map onto functional elements:
Test case: This is an individual test or group of tests. All tests in a test case belong to the same class and share a fixture.
Test fixture: The functions required to do setUp and tearDown for all the test cases in a class.
Test suite: This is a collection of test cases. Test cases in a test suite are meant to be run together.
Test runner: This is a component that runs test suites and reports the results to the user.
Let's take a closer look at some code from earlier as an example:
def f(n):
curr = n
tmp = 1
while curr != 1:
tmp = tmp + 1
if curr % 2 == 1:
curr = 3 * curr +...