In Python, as is the case with most languages, unit testing is automated within a framework that takes as input, a test case and code on which to run the test case. As output, it generates a test report on the results of having executed the test case. The unit testing framework in the Python library is implemented in the unittest module. This tutorial will describe one approach to using unittest. For a broader perspective, see the official documentation on unittest for more information.

A test case is a class containing methods for testing each requirement of a feature to ensure all aspects of the specification are implemented and function correctly. We implement test cases as subclasses of unittest.TestCase. Our first step will be to implement an empty test case and run it to be sure we have the basics in place. Following is a code listing for our initial test case in a file called term_test.py.

term_test.py
import unittest
	
class StopListTestCase(unittest.TestCase):
    # empty test case    

  • No labels