unittest 断言 assert**

import unittest

class TestAssert(unittest.TestCase):

    def testEqual(self):
        self.assertEqual(2+2, 4)
        self.assertEqual('python', 'python')
        self.assertEqual('hello', 'python')

    def testNotEqual(self):
        self.assertNotEqual(2+2, 4)
        self.assertNotEqual('python', 'hello python')

    def testTure(self):
        self.assertTrue("")
        self.assertTrue(0)
        self.assertTrue("Null")

    def testIn(self):
        self.assertIn('python', 'hello python')
        self.assertIn('good', 'hello world')


if __name__ == '__main__':

    unittest.main()

 




'''
unittest 框架的 TestCase 类提供了用于测试结果的断言方法
'''

posted @ 2020-02-15 14:25  gupanpan  阅读(99)  评论(0)    收藏  举报