Command-Line Interface
Let's explore CLI and see how it can be used with unittest module.
We'll cover the following...
The unittest module comes with a few other commands that we might find
useful.
Testing the implementation using commands
Let’s try some commands in the terminal given below and see the output.
#test_mymath2.py
import mymath
import unittest
class TestAdd(unittest.TestCase):
"""
Test the add function from the mymath library
"""
def test_add_integers(self):
"""
Test that the addition of two integers returns the correct total
"""
result = mymath.add(1, 2)
self.assertEqual(result, 3)
def test_add_floats(self):
"""
Test that the addition of two floats returns the correct result
"""
result = mymath.add(10.5, 2)
self.assertEqual(result, 12.5)
def test_add_strings(self):
"""
Test the addition of two strings returns the two string as one
concatenated string
"""
result = mymath.add('abc', 'def')
self.assertEqual(result, 'abcdef')
if __name__ == '__main__':
unittest.main()Testing different unitest commands
To find out what they are, we can run the unittest module directly and pass it ...
Ask