HTML测试报告:就是执行完测试用例后,以HTML(网页)方式将执行结果生成报告
使用HTMLTestReport生成报告
使用第三方的报告模版,生成报告
import unittest
from htmltestreport import HTMLTestReport
from unit.test_add import TestAdd
# 生成测试套件
suite = unittest.TestSuite()
#此方法把所有用例都添加进入,跟discover作用一样
# suite = unittest.TestLoader().discover('.', 'hm_02*.py')
suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestAdd))
# 实例化HTMLTestReport对象
report_path = "./report/report.html"
report = HTMLTestReport(report_path, title="单元测试报告", description="V1.0")
# 执行测试套件
report.run(suite)
报告样式
![图片[1] - 4.unitest 生成HTML测试报告 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082015024449.png)
跳过
跳过:对于一些未完成的或者不满足测试条件的测试函数和测试类,可以跳过执行
直接将测试函数标记成跳过:@unittest.skip(‘代码未完成’)
根据条件判断测试函数是否跳过:@unittest.skipIf(condition, reason)
![图片[2] - 4.unitest 生成HTML测试报告 - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082015054665.png)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END