Selenium2+python Automated 54-unittest Generation test report (htmltestrunner)

Source: Internet
Author: User

Objective

After executing the use case in bulk, the generated test report is text-less intuitive and, in order to better demonstrate the test report, it is best to generate HTML format.

UnitTest inside is unable to generate HTML format report, need to import a third-party module: Htmltestrunner

first, Import Htmltestrunner

1. This module download can not be installed through pip, can only be downloaded and then manually imported: http://tungwaiyip.info/software/HTMLTestRunner.html

2.Download The htmltestrunner.py file is the package we need to download.

3. Manually Drag to the Lib directory of the Python installation file after downloading

second, Demo Analysis

1. Download the second file under download test_htmltestrunner.py, This is the official test demo, from which you can find the usage of the Module.

2. Find this paragraph, is the official demo, test_main () in the upper part of the load test case, we do not need to Complicate.

Refer to the previous article on the line Selenium2+python automated 53-unittest batch execution (discover)

3. The core code is the following red area, This is the focus of this Article.

Iii. Generating HTML reports

1. We only need to copy the above red area code to the previous article on the basis of a slight modification can be, here are mainly three parameters:

--stream: the storage area where the test report is written to the file

--title: the subject of the test report

--description: Description of the test report

2.report_path is the address where the test report is stored

Iv. details of the test report

1. Locate the test report file, open it in a browser, and click on the detail in the view to view the details Description.

2. In order to generate test cases with a Chinese description, you can add comments in the case, such as the following comments in the test_01 script:

Class Test (unittest. TestCase):
def setUp (self):
Print "start!"

def TearDown (self):
Time.sleep (1)
Print "end!"

def test01 (self):
U ' Test login use case, account: xx password xx ' '
Print "execute test Case 01"

def test03 (self):
U ' Test log search use case, keyword: xxx '
Print "execute test Case 03"

3. Review the test report after re-running

five, Reference Code:

# Coding:utf-8
Import UnitTest
Import Htmltestrunner

def all_case ():
# Directory of cases to be executed
Case_dir = "d:\\test\\yoyotest\\case"
TestCase = Unittest. TestSuite ()
Discover = Unittest.defaultTestLoader.discover (case_dir,
pattern= "test*.py",
Top_level_dir=none)
# Discover method filters out the use cases, loops to add to the test suite
For Test_suite in Discover:
For Test_case in Test_suite:
# Add use Cases to TestCase
Testcase.addtests (test_case)
Print TestCase
Return testcase

if __name__ = = "__main__":
# return instances
# runner = Unittest. Texttestrunner ()
Report_path = "d:\\test\\yoyotest\\report\\result.html"

fp = open (report_path, "wb")
Runner = Htmltestrunner.htmltestrunner (stream=fp,
Title=u ' This is my automated test report ',
Description=u ' use case execution: ')

# Run all use cases communication QQ group: 232607095
Runner.run (all_case ())
Fp.close ()

The study process has encountered the question, may add selenium (python+java) QQ Group Exchange: 232607095

Feel that you have help, in the lower right corner of a praise it, Thank you support!

Selenium2+python Automated 54-unittest Generation test report (htmltestrunner)

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.