import unittest
import HTMLTestRunnerCN
from Study.fullstack.python.study_01 import Calculator class TestCalculator(unittest.TestCase): @classmethod def setUpClass(cls): print('最早执行') @classmethod def tearDownClass(cls): print('最后执行') def setUp(self): print('每个用例执行前执行') def tearDown(self): print('每个用例执行后执行') def test_add(self): print('执行add') result=Calculator().add(1,2) self.assertEqual(3,result,'加法错了') def test_reduc(self): print('执行reduc' ) result=Calculator().reduc(1,2) self.assertEqual(-1,result,'减法错了') def test_ride(self): print('执行ride') result = Calculator().ride( 1, 2 ) self.assertEqual( 2,result,'乘法错了' ) if __name__ == '__main__': suite = unittest.TestSuite() suite.addTest(TestCalculator('test_reduc')) suite.addTest(TestCalculator('test_add' )) runner = unittest.TextTestRunner() runner.run( suite )
if __name__ == '__main__':
suite = unittest.TestSuite() suite.addTest( TestCalculator( 'test_reduc')) suite.addTest( TestCalculator( 'test_add' ))
with open('test_report1.html','wb') as file: runner=HTMLTestRunnerCN.HTMLTestReportCN(stream=file, verbosity=2,title='测试。。。测试',description='筑泰测试',tester='李加') runner.run(suite)