zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Oracle数据库的备份及恢复策略研讨
    ast入门 (一)
    DisableThreadLibraryCalls
    写入注册表实现自启动
    QT学习1 hello程序
    打印断言函数
    注册表基本知识
    RAS详解
    const
    QT安装
  • 原文地址:https://www.cnblogs.com/jialeliu/p/13999727.html
Copyright © 2011-2022 走看看