Python-unittest unit testing framework

1. Several important concepts of unit testing
(1) Test Case
A Test Case instance is a test case. The complete test process includes setting up the environment before the test (setUp), implementing the test process code (run), and after the test Environment restoration (tearDown).
(2) Test Suite
Test Suite is used to assemble a single test case. Multiple test case sets can be executed together. Load TestCase into TestSuit instance through addTest.
(3) Test Runner
executes tests and executes results. In the unittest unit test framework, the test suit and test case are executed by the run () method provided by the TextTestRunner class. The test runner can use a graphical interface, a text interface, or return a special value to represent the result of the test execution.
(4) The test fixture
is a fixtrue for the construction and destruction of a test case environment, which is achieved by overriding the setup () and teardown () methods of testcase.
setup (): For example, establish a database connection to initialize
teardown (): For example, clear the data generated by the database and close the connection. This method is very important, to leave a clean environment for the next test case
2. Assert method

assertEqual (first, second, msg = None): Assert whether the first parameter is equal to the second parameter. If the inequality test fails, the third parameter prints the information when the test fails.
assertNotEqual (first, second, msg = None): Contrary to assertEqual (), assert whether it is not equal, continue execution if not equal, print failure information if it is equal
assertTrue (expr, msg = None): test whether the expression is TRUE
assertFalse ( expr, msg = None): test whether the expression is false

Guess you like

Origin www.cnblogs.com/dancy0dante/p/12687229.html