python中的Unittest常用方法

佐手、 提交于 2020-02-23 13:13:05

 

import unittest

class 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 true
Testing started at 上午11:38 ...

Process finished with exit code 0

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!