仍然使用上一次的测试用例进行扩展,增加resize的单元测试:
class WidgetTestCase(unittest.TestCase):
def setUp(self):
self.widget = Widget()
def tearDown(self):
self.widget = None
def testSize(self):
self.assertEqual(self.widget.getSize(), (40, 40))
def testResize(self):
self.widget.resize(100, 100)
self.assertEqual(self.widget.getSize(), (100, 100))
  测试用例管理如下:
def suite():
suite = unittest.TestSuite()
suite.addTest(WidgetTestCase("testSize"))
suite.addTest(WidgetTestCase("testResize"))
return suite
if __name__ == "__main__":
unittest.main(defaultTest = 'suite')
  在pythonWin下执行结果如下:
  >>> ..
  ----------------------------------------------------------------------
  Ran 2 tests in 0.000s
  OK
  修改测试预期:
class WidgetTestCase(unittest.TestCase):
def setUp(self):
self.widget = Widget()
def tearDown(self):
self.widget = None
def testSize(self):
self.assertEqual(self.widget.getSize(), (40,40))
def testResize(self):
self.widget.resize(50,100)
self.assertEqual(self.widget.getSize(), (100, 100))