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)
执行完成后生成测试报告用浏览器打开如下
|