unittest常用断言方法
- assertEqual(a, b)/assertNotEqual(a, b)
- assertln(a, b)/assertNotln(a, b)
- assertTrue(x)/assertFalse(x)
import unittest
class MyClass(unittest.TestCase):
def test_equal(self):
user = "admin"
self.assertEqual(user, "admin")
self.assertNotEqual("a", "b")
def test_in(self):
info = "恭喜,你的邮件已经发送成功!"
self.assertIn("成功", info)
self.assertNotIn("失败", info)
def test_true(self):
a = False
b = True
self.assertTrue(b)
self.assertFalse(a)
if __name__ == '__main__':
unittest.main()