laitimes

Finally, some big guy summed up the application of the UnitTest test framework in such detail 01.The basic introduction of the UnitTest test framework 02.Smoke test 03.Add test report 04.Assertion

author:Programmer Ah Mu

<h1 class="pgc-h-arrow-right" data-track="2" > basic introduction to the 01.UnitTest testing framework</h1>

unittest

unittest is a Python unit testing framework, similar to the JUnit framework

significance:

1. Flexible organization ui automation / interface test cases

2. Make use cases efficient

3. Assertion: Facilitates validation of test case results

4. Integration html form test report

1. A class inherits the unittest. TestCase, that is, a specific TestCase (test methods all start with test, otherwise they are not recognized by unitest, and the order of execution is based on (0-9, A-Z, a-z ))

2. The result of each use case execution is identified, and success is . , the failure is F, and the error is E

3. Use setUp(), tearDown(), setUpClass(), and tearDownClass() to lay out the environment before the use case is executed and clean up after the use case is executed

4. Add stream to the parameter to output the report to a file: you can output the html report with HTMLTestRunner.

5.3.Verbosity parameters can control the output of the execution result, 0 is a simple report, 1 is a general report, and 2 is a detailed report.

6. Multiple single test cases are grouped together, which is TestSuite

unittest, TestSuite: Test suite

unittest. TestLoader : Responsible for loading tests according to various standards and wrapping them in TestSuite

loadTestsFromNames: Returns a suite of test cases for a given set of case names

unittest. TextTestRunner: Run the use case

<h1 class="pgc-h-arrow-right" data-track="21" >02</h1>

Smoke test

'Requirements:

1. Label the use case and run only certain use cases that have a label For example, we can add _smkoe after the name of the test method to indicate that this is an important test method and needs to be regressed on a daily basis.

The key points are:

The name tagged after the test method name uses the dir(ClassName) method to get all the method names defined under the class using addTest() to dynamically add use cases

2. Customize the execution order of the use case, the long method is executed first, and the short one is executed later

<h1 class="pgc-h-arrow-right" data-track="28" >03</h1>

Integrated Html test report

time = time.strftime('%Y-%m-%d-%H-%%M', time.localtime()) # Gets the current time

dir = report path

file = open(dir, 'wb')

runner = HTMLTestRunner(stream=file, description= description information )

Service Unavailable(case)

< h1 class="pgc-h-arrow-right" data-track="35" >04.Affirm</h1>

assertion

Finally, some big guy summed up the application of the UnitTest test framework in such detail 01.The basic introduction of the UnitTest test framework 02.Smoke test 03.Add test report 04.Assertion
Finally, some big guy summed up the application of the UnitTest test framework in such detail 01.The basic introduction of the UnitTest test framework 02.Smoke test 03.Add test report 04.Assertion

Copyright notice: This article is the original article of the WeChat public account blogger "Programmer Ah Mu", please attach the original source link and this statement.

Read on