Python Interface Automation test (eight)-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 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

Related Article

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.