unittest單元測試框架之測試用例的跳過(skip) (六)
阿新 • • 發佈:2018-12-11
1.跳過測試用例的方法
- @unittest.skip("don't run this case!"):
- @unittest.skipIf(3<2,"don't run this case!"):
- @unittest.skipUnless(3>2,"don't run this case!"):
import unittest from UnittestDemo.mathfunc import * class TestMathFunc(unittest.TestCase): """測試 mathfunc.py""" # @unittest.skip("don't run this case!")# @unittest.skipIf(3<2,"don't run this case!") @unittest.skipUnless(3>2,"don't run this case!") def test_add(self): """測試加法 add()""" self.assertEqual(3,add(1,2)) self.assertNotEqual(3,add(2,2)) def test_minus(self): """測試減法 minus""" self.assertEqual(1,minus(3,2))def test_multi(self): """測試乘法 multi""" self.assertEqual(6,multi(2,3)) def test_divide(self): """測試除法 divide""" self.assertEqual(2,divide(6,3)) self.assertEqual(2.5,divide(5,2))