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 Sysprint 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-*-import unittestimport osimport timeimport htmltestrunner# use case Path Case_path = Os.path.join (OS.GETCWD () # reporting Storage Path Report_path = Os.path.join (OS.GETCWD (), ' report ') print Report_pathdef all_case (): discover = Unittest.defaultTestLoader.discover (Case_path, pattern= "test*.py", Top_level_dir=none) print Discover return Discoverif __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 path Report_abspath = Os.path.join (Report_path, "Result_" +now+ ". html") # 3, open a file, write result to this file fp = 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 add_case function return value Runner.run (All_case ()) Fp.close ()
Python Interface Automation Test (vii) UnitTest generate test report