首页 > 代码库 > python中的Unittest常用方法

python中的Unittest常用方法

 

import unittestclass SimpleUnitTest(unittest.TestCase):    def test_Fail(self):        self.failUnless(True)    def test_Fail(self):        self.failIf(False)    def test_assertEqual(self):        self.assertEqual(1,3-2)    def test_assertNotEqual(self):        self.assertNotEqual(1,3-0)    def test_assertTrue(self):        self.assertTrue(True)    def test_assertFalse(self):        self.assertFalse(False)    def test_assertIs(self):        self.assertIs(10,5+5)    def test_assertIsNot(self):        self.assertIsNot(10,5+4)    def test_assertIsNone(self):        self.assertIsNone(None)    def test_assertIsNotNone(self):        self.assertIsNotNone(we are not none ok?)    def test_asserIn(self):        self.assertIn(alone,I\‘m not alone!)    def test_asserNotIn(self):        self.assertNotIn(alone,so lonely!)if __name__==__main__:    unittest.main()

 

测试结果:

/usr/bin/python2.7 /home/alex/pycharm-3.4.1/helpers/pycharm/utrunner.py /home/alex/PycharmProjects/unittest_learn/unittest_simple.py::SimpleUnitTest::test_assertNotEqual trueTesting started at 上午11:38 ...Process finished with exit code 0

 

python中的Unittest常用方法