Unit testing
In unit testing, you tinker with a code fragment within the application. The main task is to verify that this piece of code continues to work as expected throughout the life of the application. This is accomplished by writing a test for that functionality.
A unit test can be better explained with an example. Consider a trivial function that returns the sum of two numbers. In a unit test, you invoke this function by passing two numbers as arguments, and then verify the value returned by the function is indeed the sum of the given numbers.
There are many frameworks available for writing unit tests. The examples in this chapter will be based on the built-in unit testing framework called unittest. See the heading Other unit testing tools, which gives a very short overview of alternative unit testing tools and frameworks.
Python unittest framework
The unittest
module provides the functionality to automate tests. Before we implement any tests for our application, let's first start with...