zoukankan      html  css  js  c++  java
  • unittest详解(六) 断言

    我们在执行测试用例时,怎么来判断这条用例是否通过呢?唯一的办法就是拿实际结果和预期结果进行比较,如果一致用例就是通过的,否则用例就是失败的。在python中这种比较的方法就叫做断言,unittest框架提供了一系列的断言方法。

    常用的断言方法如下:

    序号                  断言方法                       描述
    1 assertEqual(arg1, arg2, msg=None) 验证arg1=arg2,不等则fail
    2 assertNotEqual(arg1, arg2, msg=None) 验证arg1 != arg2, 相等则fail
    3 assertTrue(expr, msg=None) 验证expr是true,如果为false,则fail
    4 assertFalse(expr,msg=None) 验证expr是false,如果为true,则fail
    5 assertIs(arg1, arg2, msg=None) 验证arg1、arg2是同一个对象,不是则fail
    6
    assertIsNot(arg1, arg2, msg=None)
    验证arg1、arg2不是同一个对象,是则fail
    7 assertIsNone(expr, msg=None) 验证expr是None,不是则fail
    8 assertIsNotNone(expr, msg=None) 验证expr不是None,是则fai
    9 assertIn(arg1, arg2, msg=None) 验证arg1是arg2的子串,不是则fail
    10 assertNotIn(arg1, arg2, msg=None) 验证arg1不是arg2的子串,是则fail
  • 相关阅读:
    LeetCode 79. 单词搜索
    LeetCode 1143. 最长公共子序列
    LeetCode 55. 跳跃游戏
    LeetCode 48. 旋转图像
    LeetCode 93. 复原 IP 地址
    LeetCode 456. 132模式
    LeetCode 341. 扁平化嵌套列表迭代器
    LeetCode 73. 矩阵置零
    LeetCode 47. 全排列 II
    LeetCode 46. 全排列
  • 原文地址:https://www.cnblogs.com/eastonliu/p/9146429.html
Copyright © 2011-2022 走看看