[] The first step: introducing HTMLTestRunner package
1, download HTMLTestRunner, Download: http://tungwaiyip.info/software/HTMLTestRunner.html
Py downloaded files need to be modified to be used Python3.X, specific changes for the following:
Modify Summary:
Line 94 will be modified to import io import StringIO
Line 539, the self.outputBuffer = StringIO.StringIO () modified self.outputBuffer = io.StringIO ()
The first 642 rows will if not rmap.has_key (cls): modified if not cls in rmap:
The first line 766, the uo = o.decode ( 'latin-1') modified uo = e
The first line 775, the ue = e.decode ( 'latin-1') modified ue = e
第631行,将print >> sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)修改成print(sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime))
2. Copy the file to the HTMLTestRunner.py python installation directory / Lib folder
[Step]: write test cases with unittest
slightly
[The third step] generate HTML test report
import unittest import HTMLTestRunner if __name__ == '__main__' case_path = os.path.join(os.getcwd(), "testcases") discover = unittest.defaultTestLoader.discover(case_path, pattern="inter*.py", top_level_dir=None) report_dir = "F:\\work\\linkcld\\lds\\report\\" report_file = report_dir + "Test_Result.html" report_stream = open(report_file, "wb") runner = HTMLTestRunner.HTMLTestRunner(stream=report_stream, title=u"接口自动化测试报告", description=u"用例执行情况如下:") runner.run(discover) report_stream.close()
Complete follow-up test to see reports generated in the appropriate directory!