目录
unittest
点击查看代码
import unittest
from htmltestreport import HTMLTestReport
class TestOne(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
print(f'setUpClass')
@classmethod
def tearDownClass(cls) -> None:
print(f'tearDownClass')
def setUp(self) -> None:
print(f'setUp')
def tearDown(self) -> None:
print(f'tearDown')
def test_01(self):
self.assertTrue(1 == 1)
def test_02(self):
self.assertEqual(1, 1, 'this is message')
if __name__ == '__main__':
"""pycharm里面执行是通过pycharm的插件执行的 自动识别了测试用例
如果要生成报告 需要通过python xxx.py执行
可以自己创建(填写脚本路径和工作目录 防止使用pycharm的工作目录)或者在没有单元测试的执行一次生成
"""
# run test
# unittest.main()
# generate report
test_suit = unittest.TestSuite()
test_suit.addTest(unittest.makeSuite(TestOne))
report = HTMLTestReport('report.html', "Title", "description")
print(f'finished')
res = report.run(test_suit)
print(f'finished')
report.generateReport(test_suit, res)