In this section, we are going to create unit tests. To do this, we will create two scripts. One will be your normal script and the other will contain the code for testing.
First, create a script named arithmetic.py and write the following code in it:
# In this script, we are going to create a 4 functions: add_numbers, sub_numbers, mul_numbers, div_numbers.
def add_numbers(x, y):
return x + y
def sub_numbers(x, y):
return x - y
def mul_numbers(x, y):
return x * y
def div_numbers(x, y):
return (x / y)
In the preceding script, we created four functions: add_numbers, sub_numbers, mul_numbers, and div_numbers. Now, we are going to write test cases for these functions. First, we will learn how we can write test cases for the add_numbers function. Create a test_addition.py script and write the following code in it:
import arithmetic
import unittest
# Testing...