uinttest断言assert
1、简单案例
import unittest class Test(unittest.TestCase): def test01(self): # 判断 a = b a = "100" b = "100" self.assertEqual(a, b) def test02(self): # 判断a是否是b的子集 a = "1" b = "123456789" self.assertIn(a, b) def test03(self): # 判断a为True a = True self.assertTrue(a) def test04(self): a = "jiale" b = 123 self.assertEqual(a, b,msg = "失败原因:%s != %d"%(a,b)) # msg参数,遇到异常后自定义输出信息 if __name__ == "__main__": unittest.main()
2、unittest常用的断言方法
1.assertEqual(self, first, second, msg=None) --判断两个参数相等:first == second 2.assertNotEqual(self, first, second, msg=None) --判断两个参数不相等:first != second 3.assertIn(self, member, container, msg=None) --判断是字符串是否包含:member in container 4.assertNotIn(self, member, container, msg=None) --判断是字符串是否不包含:member not in container 5.assertTrue(self, expr, msg=None) --判断是否为真:expr is True 6.assertFalse(self, expr, msg=None) --判断是否为假:expr is False 7.assertIsNone(self, obj, msg=None) --判断是否为None:obj is None 8.assertIsNotNone(self, obj, msg=None) --判断是否不为None:obj is not None
参考自:https://www.cnblogs.com/yoyoketang/p/6691270.html
本文来自博客园,作者:{Tester十点半},转载请注明原文链接:https://www.cnblogs.com/jialeliu/p/13999727.html