Writing unit tests for the application
It is time to write some unit tests for the application. We will make a new subclass of unittest.TestCase
to hold all the unit tests.
Setting up a test package
As a first step, let's create a new package for holding the test cases. Create a new directory called test
at the same level where you have the rest of the code. Next, create two new files inside this test
directory, as shown here:
The test_wargame.py
module is where new unit tests will be created. To recognize the directory as a Python package, add an empty __init__.py
file.
Tip
If you haven't already, read Chapter 3, Modularize, Package, Deploy! for details on creating a Python package.
Creating a new class for unit testing
The test_wargame.py
file can also be found in the supporting code. It has all the code to be discussed next. In the following discussion, it is assumed that you will code from scratch to an empty file.
Create a new subclass of unittest.TestCase
, and call it TestWarGame
or any name...