python unittest生成测试报告
程序员文章站
2024-03-21 22:34:58
...
python default.py
import unittest
from tools.HTMLTestRunner import HTMLTestRunner
# HTMLTestRunner这个模块网上可下载
# 测试用例全部放在cases路径下,以iwebshop_test开头
suite = unittest.defaultTestLoader.discover("./cases", pattern="iwebshop_test*")
# runner= unittest.TextTestRunner()
# runner.run(suite)
#这里必须是“wb”
with open("./report.html", "wb") as f:
# 用HTMLTestRunner这个py文件生成runner对象
runner = HTMLTestRunner(stream=f, title="简单测试报告", description="测试用例一共6涛")
#文件路径如下
runner.run(suite)
路径如下:
iwebshop_test1.py
import unittest
class TestA(unittest.TestCase):
def setUp(self):
print("setup方法执行了")
def tearDown(self):
print("teardown方法执行了")
def test01(self):
print("haha")
def test02(self):
print("hehe")
if __name__ == '__main__':
unittest.main()
生成的测试报告:
上一篇: Yii2之类自动加载