Introduction to the framework of automated testing of Python interfaces

Starting today, I will introduce you to a Python interface automation testing framework. The framework is based on Python + unittest + requests + HTMLTestRunner. You can also see the use of this framework on the Internet. Based on this framework, I will make some changes and add some such as The method of obtaining tokens, the method of passing parameters between interfaces, and the optimization of test report display effects, etc., gradually optimize this test framework. The current company is also based on this framework to optimize the interface automation test.

 

The directory structure of the framework:

 

The overall design idea is as follows:

 

Common mainly stores functional methods, including the following: configEmail.py: This file is mainly used to configure the subject and text of the sent email, and the logic to send the test report and copy it to the mailbox of the relevant person. configHttp.py: This file is mainly used to make http requests through get, post, put, delete and other methods, and get the request response. HTMLTestRunner.py: mainly to generate test report related Log.py: call this method, used to print the generated log

result: store test results and logs: logs: generated log file report.html: generated test report

testCase stores test cases: test01case.py: reads the use cases in userCase.xlsx, and uses unittest to perform assertion verification

testFile / case stores test files and other Excel files: userCase.xlsx: For the interface in the following test_api.py interface service, three simple test cases are designed, such as the parameter is null, the parameter is incorrect, etc. caselist.txt: The configuration will be executed testCase Which use-case files in the directory are preceded by # means not to be executed. When the project is too large and there are enough use cases, we can use this switch to determine which use cases of which interfaces are executed this time. config.ini: configuration items such as database, mailbox, interface, etc., used for convenient calling and reading. getpathInfo.py: get the absolute path of the project geturlParams.py: get the URL, parameters, method, etc. of the interface readConfig.py: the method of reading the configuration file, and return the content in the file readExcel.py: the method of reading Excel runAll.py: Start to implement interface automation, and run the file directly after the project is deployed. Test_api.py: Provide interface service for local testing

Test report display results:

 

Published 17 original articles · Like1 · Visits 819

Guess you like

Origin blog.csdn.net/weixin_45433031/article/details/105132663