class TestSuite(unittest.TestCase):
def setup(self):
pass;
def tearDown(self):
pass;
def testAdd(self):
res = add(100,4);
self.assertEqual(res,104);
self.assertEqual(add(-1,23),22);
def testSub(self):
res = sub(100,4);
self.assertEqual(res,96);
self.assertEqual(sub(23,32),0);
def testMul(self):
res = mul(100,4);
self.assertEqual(res,400);
def testDiv(self):
res = div(100,4);
self.assertEqual(res,25);
self.assertEqual(div(1,0),0);
self.assertEqual(div(2,0),1);
def suite():
suite = unittest.TestSuite();
suite.addTest(TestSuite("testAdd"));
suite.addTest(TestSuite("testSub"));
suite.addTest(TestSuite("testMul"));
suite.addTest(TestSuite("testDiv"));
return suite;
if __name__ == "__main__":
unittest.main(defaultTest = 'suite')
(2)运行测试case
python case.py (3)结果如下, 其中有2个case运行失败,原因是预期结果不正确。
|