Unit testing
Unit testing is a technique for automated testing of small sections ("units") of code to ensure that the components of a larger application are working as intended, independently of each other.
There are many frameworks for this in almost every language. In Python, we will be using the unittest
module, as this is included with the language and is the most common framework used in the Python applications.
To add unit tests to our calculator module, we will create an additional module in the same directory named test.
Inside that will be three files: __init__.py
(used to denote that a directory is a Python package), test_Calculator.py,
and test_Operation.py
.
After creating this additional module, the structure of the code will be the same as shown in the following image:
Next, we will modify the test_Operation.py
file to include a test case for the Operation
class. As always, this will start with the required imports for the modules we will be using:
import unittest from...