unittest framework - test case management

Add use case management

The front is for unit testing a single add method. If you need to test multiple methods, what should you do? Such as adding a Sub method for unit test verification. (Blue is the new sub method)

We need to unit test both the add and sub methods. Then we need to add a class as TestCase for the new sub method.

The test results are as follows:


Use case common part merge

In this example, each test class has SetUp() and tearDown() methods, and the content of the two methods is the same, for printing the start and end prompt statements, can they be combined?

Separately define a parent class Test_StarEnd() to place the SetUp() and tearDown() methods. Test_StarEnd() inherits unnitest.TestCase. Re-define the classes that test the add and sub methods, and inherit the parent class Test_StarEnd(). Because the parent class Test_StarEnd() inherits unnitest, the subclasses Test_add() and Test_sub can also use the assertion method in unittest.

When finally running the test case, it is also more concise:


use case execution order

Execution order rules: 0-9 according to the number and alphabetical order of the test class or test method, AZ is executed

So how to execute it in a custom order?

It can be controlled as follows:



Test case integrated framework management

The previous test cases and execution are written in a file. When the number of test cases increases, the execution and management of test cases become very troublesome. Therefore, use cases need to be managed according to specific functional modules.

Case:

The Test_Project file directory contains 4 python files:

  • I--StartEnd.py SetUp and TearDown management
  • I--calculatory.py Implementation of addition and subtraction methods
  • I--test_add.py Addition test case
  • I--test_sub.py Subtraction test case
  • I--runtest.py use case execution management

calculatory.py implementation of addition and subtraction methods



StartEnd.py SetUp and TearDown management


test_add.py Addition test case



test_sub.py Subtraction test case



runtest.py use case execution management


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325396064&siteId=291194637