One: Understanding UnitTest
Unittest:python internal Unit test module; junit similar to Java;
II: UnitTest Basic use
1:import UnitTest
2: Define a test class that inherits UnitTest. TestCase
3:setup and teardown, each test function is run before and after execution
4: Define test function, name starts with test
5: The main call assertequal, assertraises and other assertion methods to determine whether the program execution results and expected values are consistent
6: Call Unittest.main () to start the test
(1) Below we look at the specific code, as well as the results of the operation:
(2) In fact, we can also add parameters to Unittest.main (): Print the details as shown in:
The verbosity here is an option that identifies the information complexity of the test results, with three values:
0 (silent mode): can only get the total number of test cases and total results such as a total of 100 failed 20, the success of 80
1 (default mode): Very similar to silent mode, except for each successful use case preceded by a ".", each failed use case preceded by an "F"
2 (verbose mode): test results show all relevant information for each test case
(3) When the use case execution error, will give the error prompt, such as: we can according to the error prompt to locate the error location;
Above, we are the simplest example of unittest, but it is also a very important beginning.
Python UnitTest Learning notes (i)