[python learning] unit test framework unittest-basic (1)-31

Unittest : It is a unit testing framework for python. The unittest unit test provides a solution for creating test cases, test suites and batch execution. After installing pyhton, unittest comes with it directly, and it can be used directly by importing unittest. As a unit testing framework, unittest is also an agile test for the smallest module of the program. In automated testing, it is necessary to know the unit testing framework of the language being used. Use the unit testing framework to create a class that inherits the TestCase of unittest, so that each case can be regarded as a minimum unit, organized by the test container, and executed directly at that time, and the test report is introduced at the same time.

Unittest module: TestCace (test case), TestSuite (test set), TestLoader (load use case), TestRunner (execute use case)

import unittest

# 定义测试类
class TestDemo(unittest.TestCase):
    def test_a_logo(self):
        print("测试用例1")
    def test_b_logo(self):
        print("测试用例2")

if __name__ == '__main__':
    unittest.main()

------------------------打印结果------------------------

Ran 2 tests in 0.005s

OK
测试用例1
测试用例2

To sum up, these four modules (TestCase, TestSuite, TestLoader, TextTestRunner) will start key functions in the subsequent unit tests, all of which belong to the classes in the unittest module.

Guess you like

Origin blog.csdn.net/admins_/article/details/122247437