方法 | 检查 | 版本 |
assertEqual(a,b) | a==b | |
assertNotEqual(a,b) | a!=b | |
assertTrue(x) | bool(x)is True | |
assertFalse(x) | bool(x)is False | |
assertIs(a,b) | a is b | 3.1 |
assertIsNot(a,b) | a is not b | 3.1 |
assertIsNotNone(x) | x is not None | 3.1 |
assertIn(a,b) | a in b | 3.1 |
assertNotIn(a,b) | a not in b | 3.1 |
assertIsInstance(a,b) | isinstance(a,b) | 3.2 |
assertNotIsInstance(a,b) | not isinstance(a,b) | 3.2 |
例如:
import unittest class TestAssert(unittest.TestCase): def test_equal(self): self.assertEqual(2+2, 4) self.assertEqual("python", "python") self.assertNotEqual("hello", "python") def test_in(self): self.assertIn("hello", "hello world") self.assertNotIn("hi", "hello") def test_true(self): self.assertTrue(True) self.assertFalse(False) if __name__ == '__main__': unittest.main
来源:博客园
作者:zhengzi
链接:https://www.cnblogs.com/kite123/p/11541880.html