python 的testunit.TestCase
import unittest
class ArithTestSupper(unittest.TestCase):
def setUp(self):
print(“Setting up ArithTest cases”)
def tearDown(self):
print(“Cleaning up ArithTest cases”)
class ArithTest(ArithTestSupper):
def runTest(self):
“”” Test addition and success”“”
self.failUnless(1+1==2,’one plus one fails!’)
self.failIf(1+1!=2,’one plus one fails again!’)
class ArithTestFail(ArithTestSupper):
def runTest(self):
“”“Test addition and fail.”“”
self.failUnless(1+1==2,’one plus one fails’)
self.failIf(1+1!=2,”one plus one fails again!”)
self.failUnlessEqual(1+1,2,”more touble with one plus one!”)
self.failIfEqual(1+1,2,”expected failure here!”)
self.failIfEqual(1+1,2,”second failure here!”)
def suite_2():
suite = unittest.TestSuite()
suite.addTest(ArithTest())
suite.addTest(ArithTestFail())
return suite
if name ==’main‘:
runner = unittest.TextTestRunner()
test_suite = suite_2()
runner.run(test_suite)
套件测试