[ unittest ] 使用初体验

import unittest
from cal import Calculate
class Mytest(unittest.TestCase):
        
    def setUp(self):
        self.cal = Calculate()
        # print('start up...')
    def test_cal(self):
        self.assertEqual(self.cal.addit(3,2),5,'Result Wrong')
    def test_cal1(self):
        self.assertEqual(self.cal.addit(2,3),5,'Result Wrong')
    def tearDown(self):
        pass
        # print('End...')
def suite():
    suite = unittest.TestSuite()
    #addTests接收一个可迭代的实例,来自testcase和testsuite
    #基类unittest.TestCase接收methodName,
    suite.addTests([Mytest('test_cal'),Mytest('test_cal1')])
    return suite

if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    runner.run(suite())

 

你可能感兴趣的:([ unittest ] 使用初体验)