- For this example, we'll assume that the unittest test cases are the same module as the code being tested. Import the unittest and unittest.mock modules:
import unittest from unittest.mock import *
The unittest module is simply imported. To use the features of this module, we'll have to qualify the names with unittest.. The various names from unittest.mock were all imported so the names can be used without any qualifier. We'll use a number of features of the mock module, and the long qualifying name is awkward.
- Include the code to be tested. This is shown previously.
- Create the following skeleton for testing. We've provided one class definition, plus a main script that can be used to execute the tests:
class GIVEN_data_WHEN_save_data_THEN_file(unittest.TestCase): ...