使用unittest.TestSuite组织执行用例

来源:互联网 发布:百姓网端口有什么用 编辑:程序博客网 时间:2024/06/06 04:55
#-*-coding:utf-8-*-'''Created on 2016年4月11日@author: Zroad'''import calculatorimport unittestclass TestSuiteForCount(unittest.TestCase):    def setUp(self):        print "Test start ......"    def testAdd(self):        j = calculator.Count(2,5)        self.assertEqual(j.add(), 5, "Your input is not 7!")    def testAdd1(self):        j = calculator.Count(10,10)        self.assertEqual(j.add(), 20, msg="Your input is not 20")    def tearDown(self):        print "Test end .........."if __name__ == "__main__":    #1、使用TestSuite构建测试集,可保证有序地执行各用例    suite = unittest.TestSuite()    suite.addTest(TestSuiteForCount("testAdd"))    suite.addTest(TestSuiteForCount("testAdd1"))    #2、不使用unittest.main()执行测试用例,    #可使用unittest.TextTestRunner()类的run方法来运行    runner = unittest.TextTestRunner()    runner.run(suite)
0 0
原创粉丝点击