[ 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())

 

上一篇:jmockit中文网 expectations 入门


下一篇:使用python和tushare股票交易日历数据,判断节假日周末休市