August 2018
Intermediate to advanced
466 pages
10h 23m
English
In the previous example, we saw how we could use the assertEqual() method to compare the two values to return either True or False. Here is an example of the built-in unittest module to compare two values:
$ cat chapter13_4_unittest.py#!/usr/bin/env python3import unittestclass SimpleTest(unittest.TestCase): def test(self): one = 'a' two = 'a' self.assertEqual(one, two)
Using the python3 command-line interface, the unittest module can automatically discover the test cases in the script:
$ python3 -m unittest chapter13_4_unittest.py.----------------------------------------------------------------------Ran 1 test in 0.000sOK
Besides comparing two values, here are more examples of testing if the expected value is