1 import unittest 2 3 4 def add(a: int,b: int): 5 return a+b 6 7 def multi(a: int, b: int): 8 return a*b 9 10 class MyTEST(unittest.TestCase): 11 def setUp(self) -> None: 12 return super().setUp() 13 14 def test_add(self): 15 self.assertEqual(add(1,1), 2, '加法计算错误') 16 17 18 def test_mul(self): 19 self.assertEqual(multi(1,1), 1, '乘法计算错误') 20 21 def tearDown(self) -> None: 22 return super().tearDown() 23 24 25 if __name__ == '__main__': 26 suite = unittest.TestSuite() 27 suite.addTest(MyTEST('test_add')) 28 suite.addTest(MyTEST('test_mul')) 29 runner = unittest.TextTestRunner() 30 runner.run(suite)
仅供参考