SELENIUM2 Learning: Unit Test Framework (5): HTML test Report

Source: Internet
Author: User

1.1 HTML test Report 1.1.1 Download Htmltestrunner

: http://tungwaiyip.info/software/HTMLTestRunner.html

Store the downloaded htmltestrunner.py in Lib in the Python installation directory, as

1.1.2 Configuration Htmltestrunner

Since htmltestrunner.py is developed based on Python2, the htmltestrunner.py file needs to be modified.

    1. 94 Rows

Mport Stringio change to import io.

    1. 539 rows

Self.outputbuffer = Stringio.stringio () changed to Self.outputbuffer = Io. Bytesio ()

    1. 631 Rows

Print >>sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime) to

Print (Sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime))

    1. 642 rows

If not Rmap.has_key (CLS): Change to If not CLS in Rmap:

    1. 766 rows

UO = O.decode (' latin-1 ') changed to Uo=o

    1. 772 rows

UE = E.decode (' latin-1 ') changed to UE = E

1.1.3 Editing execution files

The execution of the file is still a calculation file, the same as the 7.3.4 py file, the Runtest file is modified, the results are as follows:

runtest:htmlRPT.py

ImportUnitTest fromHtmltestrunnerImportHtmltestrunnerImport Time#define the catalog of test cases as the current directoryTest_dir ='./'Discover= Unittest.defaultTestLoader.discover (Test_dir, pattern='test*.py')if __name__=='__main__': Now= Time.strftime ("%y%m%d-%h%m%s") filename= Test_dir +'/'+'Report_'+ Now +'. html'FP= open (filename,'WB') Runner= Htmltestrunner (STREAM=FP,#stream Specifies the test report filetitle='Calculator Test Report',#Test Report titledescription='use cases are performed as follows:')#subtitleRunner.run (Discover)

1. Add import File

From Htmltestrunner import Htmltestrunner

2, avoid each time each execution of the report is overwritten, so the report name contains the current time

now = Time.strftime ("%y%m%d-%h%m%s")

The current time is displayed and assigned to the now variable in the form of a month-by-hour date.

filename = test_dir + '/' + ' Report_ ' + Now + '. html '

The report name is under current directory: Reporting time. html

3, in order to ensure that the report is clear and understandable, it is recommended that the classes and methods in the file being executed use the ' ... ' note stating that, because ' ... ' is a doc string-type comment that is not displayed when normally invoked, but Htmltestrunner can be read successfully. Such as:

test_add.py

#0517008:suite:add fromCalculatorImportCountImportUnitTestclassTestadd (unittest. TestCase):" "addition Calculation" "    defsetUp (self):Print('Test Add Start')            defTearDown (self):Print('Test Add over')    deftest_add1 (self):" "addition calculation 1: Success" "J= Count (2,3) self.assertequal (J.add (),5,msg='addition 2+3=5: Wrong 1')    deftest_add2 (self):" "addition calculation 2: Failure" "J= Count (3,3) self.assertequal (J.add (),5,msg='addition 3+3=5: Wrong 2')if __name__=='__main__': Unittest.main ()
1.1.4 Execution Results

Click Detail to see all the method execution under the class, click fail to see the reason for the failure.

SELENIUM2 Learning: Unit Test Framework (5): HTML 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.