使用unittest.TestSuite组织执行用例

  • Post author:
  • Post category:其他

#-*-coding:utf-8-*-
'''
Created on 2016年4月11日

@author: Zroad
'''

import calculator
import unittest

class 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)

版权声明:本文为u010039733原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。