手动生成一个测试用例.py
import unittest
class Untestbg(unittest.TestCase):
def setUp(self) -> None:
print("start")
def test01(self):
a = 1
self.assertEqual(a,2)
def test02(self):
b = 2
self.assertEqual(b,3)
def test03(self):
c = 3
self.assertEqual(c,3)
def test04(self):
d = 4
self.assertEqual(d,4)
def tearDown(self) -> None:
print("end")
if __name__ == '__main__':
unittest.main()
手动生成测试报告.py
import unittest
from ceshibaogao.uniest import Untestbg
from datadome.HTMLTestRunner import HTMLTestRunner
class CeshiBaog(object):
def Htmltest(self):
suite = unittest.TestSuite() # 创建测试套件
case_list = ["test01","test02","test03","test04"]
for case in case_list:
suite.addTest(Untestbg(case))
with open("../report.html", "wb") as f:
HTMLTestRunner(
stream=f,
title="单元测试",
description="测试一期",
verbosity=2
).run(suite)
if __name__ == '__main__':
ceshibaog = CeshiBaog()
ceshibaog.Htmltest()
查看生成的测试报告.html
查看生成单元测试报告