标签:str unittest 结构 png stl ssm open print title
目录结构如下:
test1.py
1 import unittest 2 3 4 class Test(unittest.TestCase): 5 ‘‘‘我的第一个测试类‘‘‘ 6 7 @classmethod 8 def setUp(self): 9 pass 10 11 def test_case_1(self): 12 ‘‘‘测试2是否等于2‘‘‘ 13 self.assertEqual(2, 2, ‘不相等2!=2‘) 14 15 def test_case_2(self): 16 ‘‘‘测试2是否等于3‘‘‘ 17 self.assertEqual(2, 3, ‘不相等2!=3‘) 18 19 @classmethod 20 def tearDown(self): 21 pass 22 23 24 if __name__ == ‘__main__‘: 25 unittest.main()
test2.py
1 import unittest 2 3 4 class Test(unittest.TestCase): 5 ‘‘‘我的第二个测试类‘‘‘ 6 7 @classmethod 8 def setUp(self): 9 pass 10 11 def test_case_3(self): 12 ‘‘‘测试20是否等于20‘‘‘ 13 self.assertEqual(20, 20, ‘不相等20!=20‘) 14 15 def test_case_4(self): 16 ‘‘‘测试2是否等于3‘‘‘ 17 self.assertEqual(20, 30, ‘不相等20!=30‘) 18 19 @classmethod 20 def tearDown(self): 21 pass 22 23 24 if __name__ == ‘__main__‘: 25 unittest.main()
runtest123.py
1 from HTMLTestRunner import HTMLTestRunner 2 import unittest 3 import time 4 5 if __name__ == ‘__main__‘: 6 discover = unittest.defaultTestLoader.discover(‘./‘, pattern=‘test*.py‘) 7 print(discover) 8 9 now_time = time.strftime(‘%Y-%m-%d %H_%M_%S‘) 10 file_name = ‘testreslut_‘ + now_time + ‘.html‘ 11 fp = open(file_name, ‘wb‘) 12 runner = HTMLTestRunner(stream=fp, 13 title=‘我的测试报告‘, 14 description=‘用例执行情况‘) 15 runner.run(discover) 16 fp.close()
生成的报告:
selenium - HTML测试报告 - 生成测试报告(testloader的discover添加用例方法)
标签:str unittest 结构 png stl ssm open print title
原文地址:https://www.cnblogs.com/xiaochongc/p/12606131.html