test_HTMLTestRunnerCN.py
代码如下:
1 from calculator import Count 2 import unittest 3 import HTMLTestRunnerCN 4 5 #测试两个整数相加 6 class TestAdd(unittest.TestCase): 7 def setUp(self): 8 print('Test Add Start!') 9 10 def test_add(self): 11 j = Count(2, 3) 12 self.assertEqual(j.add(), 5) 13 14 def test_add2(self): 15 j = Count(41, 76) 16 self.assertEqual(j.add(), 117) 17 18 def tearDown(self): 19 print('Test Add End!') 20 21 #测试两个整数相减 22 class TestSub(unittest.TestCase): 23 def setUp(self): 24 print('Test Sub Start!') 25 26 def test_sub(self): 27 k = Count(2, 3) 28 self.assertEqual(k.sub(), -1) 29 30 def test_sub2(self): 31 k = Count(71, 46) 32 self.assertEqual(k.sub(), 25) 33 34 def tearDown(self): 35 print('Test Sub End!') 36 37 if __name__ == '__main__': 38 #构造测试集 39 suite = unittest.TestSuite() 40 suite.addTest(TestAdd('test_add')) 41 suite.addTest(TestAdd('test_add2')) 42 suite.addTest(TestSub('test_sub')) 43 suite.addTest(TestSub('test_sub2')) 44 #运行测试集合 45 filePath = 'E:/123/Report.html' 46 fp = open(filePath, 'wb') 47 #生成报告的Title,描述 48 runner = HTMLTestRunnerCN.HTMLTestReportCN( 49 stream=fp, 50 title='自动化测试报告', 51 #description='详细测试用例结果', 52 tester='Nobita' 53 ) 54 #运行测试用例 55 runner.run(suite) 56 # 关闭文件,否则会无法生成文件 57 #fp.close()