Python Interface Automation Test (vii) UnitTest generate test Report

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.