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.
- 94 Rows
Mport Stringio change to import io.
- 539 rows
Self.outputbuffer = Stringio.stringio () changed to Self.outputbuffer = Io. Bytesio ()
- 631 Rows
Print >>sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime) to
Print (Sys.stderr, ' \ntime Elapsed:%s '% (self.stoptime-self.starttime))
- 642 rows
If not Rmap.has_key (CLS): Change to If not CLS in Rmap:
- 766 rows
UO = O.decode (' latin-1 ') changed to Uo=o
- 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