Use case management problem solved, the next thing to consider is to report my problem, here to generate test reports mainly used to htmltestrunner.py this module, the following is a brief introduction to how to use:
First, download Htmltestrunner download:
This module cannot be installed by PIP and can only be downloaded and installed as follows:
- python2.x version: http://tungwaiyip.info/software/HTMLTestRunner.html
- python3.x version: http://hzqldjb.blog.51cto.com/9587820/1590802
Second, the MAC configuration:
1, the terminal into the Python environment
2. Enter:
Import SYS Print Sys.path
3, find the path of the Site-packages folder and copy the downloaded htmltestrunner.py file to this folder 4, in the Python environment, input import Htmltestrunner No error is installed success
third, use the module to generate reports:
1. Directory Structure
- There are baidu,httpbin two packages under case package
- There are two test py files under each package, respectively
- Each of the test_00x.py files has 2 test case
- run_all_case.py file: Used to execute all test case and generate report
2. The following reports are generated after the operation:
3. The run_all_case.py code is as follows:
#-*-coding:utf-8-*-ImportUnitTestImportOSImport TimeImportHtmltestrunner#use case PathCase_path =Os.path.join (OS.GETCWD ())#Report Storage PathReport_path = Os.path.join (OS.GETCWD (),' Report')PrintReport_pathdefall_case (): Discover= Unittest.defaultTestLoader.discover (Case_path, pattern="test*.py", top_level_dir=None)PrintDiscoverreturnDiscoverif __name__=='__main__': #1. Get the current time so that it is easy to use below. now = Time.strftime ("%y-%m-%d-%h_%m_%s", Time.localtime (Time.time ()))#2. HTML report File pathReport_abspath = Os.path.join (Report_path,"Result_"+now+". html") #3. Open a file to write result tofp = open (Report_abspath,"WB") Runner= Htmltestrunner.htmltestrunner (stream=FP, title=u'Interface Automation test Report, test results are as follows:', Description=u'use case execution:') #4. Call the Add_case function return valueRunner.run (All_case ()) Fp.close ()
Python Interface Automation test (eight)-unittest-generate test Report