1.下载并安装HTMLTestRunner.py
(1) 下载:原始版本下载地址(支持python2.0): http://tungwaiyip.info/software/HTMLTestRunner.html
(2) 将HTMLTestRunner.py文件拷贝到Python\lib目录下
(3) 验证:能正常导入即可
2.代码实现测试报告实例:
(1) 创建testRuner.py,代码实例如下:
import time
import framework.public_functions as pf
import os
import HTMLTestRunner
#调用createTestSuite()方法
testunit = pf.create_test_suite()
#定义log日志文件的目录和名称
now = time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime(time.time()))
#定义HTML报告的目录和名称
filePath = os.path.join(os.path.dirname(__file__), '../result/report/').replace('\\', '/')
fileName = filePath + now + "_result.html"
fp = open(fileName, "wb")
#设置HTML报告的title和description信息
runner = HTMLTestRunner.HTMLTestRunner(
stream = fp,
title = u'RDIS测试报告',
description = u'用例执行情况:')
#启动测试套件
runner.run(testunit)
fp.close()