1、HTMLTestRunner安装 使用如下命令安装即可: pip install caterpillar-HTMLTestRunner
2、HTMLTestRunner使用 比如test01.py中
测试用例代码如下: import unittest class TestDemo01(unittest.TestCase): def test_01(self): print("in test_01...") def test_02(self): print("in test_02...") def test_03(self): print("in test_03...")
测试套文件中代码如下: import unittest import os from demo.test01 import TestDemo01 from HTMLTestRunner import HTMLTestRunner report_title="测试报告标题" report_desc="测试报告描述" report_path="./report" report_file=os.path.join(report_path,"report.html") if not os.path.exists(report_path): os.mkdir(report_path) suite = unittest.TestSuite() suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDemo01)) with open(report_file ,"wb") as report: runner = HTMLTestRunner(stream=report, title=report_title, description=report_desc) runner.run(suite)
执行完成后生成测试报告用
浏览器打开如下:

本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理
21天更文挑战,赢取价值500元大礼,还有机会成为签约作者!