常用的断言方法如下:

assertFalse:为假时返回True;self.assertFalse(表达式,“表达式为true时打印的message”)

assertTrue:为真时返回True;self.assertTrue(表达式,“表达式为false时打印的message”)

asserEqual:相等返回True;self.assertEqual(表达式1,表达式2,“表达式1不等于表达式2时打印的message”)

assertNotEqual:不相等返回True;self.assertNotEqual(表达式1,表达式2,“表达式1等于表达式2时打印的message”)

assertIsNone:不存在,则pass;self.assertIsNone(表达式,“如果表达存在打印的message”)

assertIsNotNone:存在,则pass;self.assertIsNotNone(表达式,“如果表达式不存在打印的message”)

在官方文档里面看到的整理一下,有些还来不及翻译。

assertAlmostEqual(first, second[, places, ...])

适用于小数,place是应最少几位相等布尔值才为1(默认为7),如果在place位以内不同则断言失败。

assertDictContainsSubset(expected, actual[, msg])

检查实际是否超预期

assertDictEqual(d1, d2[, msg])

前后字典是否相同

assertEqual(first, second[, msg])

前后两个数不等的话,失败

assertFalse(expr[, msg])

检查表达式是否为假

assertGreater(a, b[, msg])

和self.assertTrue(a > b)用法一样,但是多了设置条件 .

assertGreaterEqual(a, b[, msg])

和self.assertTrue(a > =b)用法一样,但是多了设置条件 .

assertIn(member, container[, msg])

self.assertTrue(a in b)

assertIs(expr1, expr2[, msg])

assertTrue(a is b)

assertIsInstance(obj, cls[, msg])

Isinstance(a,b)

assertIsNone(obj[, msg])

Obj is none.

assertIsNot(expr1, expr2[, msg])

a is not b.

assertIsNotNone(obj[, msg])

Obj is not none.

assertItemsEqual(expected_seq, actual_seq[, msg])

一个无序的序列特异性的比较。

assertLess(a, b[, msg])

Just like self.assertTrue(a < b), but with a nicer default message.

assertLessEqual(a, b[, msg])

Just like self.assertTrue(a <= b), but with a nicer default message.

assertListEqual(list1, list2[, msg])

List1与list2是否相等.

assertMultiLineEqual(first, second[, msg])

断言,2个多行字符串是相等的

assertNotAlmostEqual(first, second[, ...])

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is less than the given delta.

assertNotAlmostEquals(first, second[, ...])

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is less than the given delta.

assertNotEqual(first, second[, msg])

Fail if the two objects are equal as determined by the ‘==’

assertNotEquals(first, second[, msg])

Fail if the two objects are equal as determined by the ‘==’

assertNotIn(member, container[, msg])

Just like self.assertTrue(a not in b), but with a nicer default message.

assertNotIsInstance(obj, cls[, msg])

Included for symmetry with assertIsInstance.

assertNotRegexpMatches(text, unexpected_regexp)

如果文本匹配正则表达式,将失败。

assertRaises(excClass[, callableObj])

除非excclass类抛出异常失败

assertRaisesRegexp(expected_exception, ...)

认为在引发异常的情况下消息匹配一个正则表达式。

assertRegexpMatches(text, expected_regexp[, msg])

测试失败,除非文本匹配正则表达式。

assertSequenceEqual(seq1, seq2[, msg, seq_type])

有序序列的相等断言 (like lists and tuples).

assertSetEqual(set1, set2[, msg])

A set-specific equality assertion.

assertTrue(expr[, msg])

Check that the expression is true.

assertTupleEqual(tuple1, tuple2[, msg])

A tuple-specific equality assertion.

assert_(expr[, msg])

Check that the expression is true.

Python的unittest框架的断言总结的更多相关文章

  1. selenium + python自动化测试unittest框架学习(一)selenium原理及应用

    unittest框架的学习得益于虫师的<selenium+python自动化实践>这一书,该书讲得很详细,大家可以去看下,我也只学到一点点用于工作中,闲暇时记录下自己所学才能更加印象深刻. ...

  2. python之unittest框架实现接口测试实例

    python之unittest框架实现接口测试实例 接口测试的方法有很多种,具体到工具有postman,jmeter,fiddler等,但是工具的局限性是测试数据的组织较差,接口的返回工具的判断有限, ...

  3. selenium + python自动化测试unittest框架学习(二)

    1.unittest单元测试框架文件结构 unittest是python单元测试框架之一,unittest测试框架的主要文件结构: File >report >all_case.py &g ...

  4. python的unittest框架中的assert断言

    unittest框架自带断言,如果想用assert断言,一定要引入unittest.TestCase框架才行,不然不会自动识别assert断言

  5. selenium自动化测试、Python单元测试unittest框架以及测试报告和日志输出

    部分内容来自:https://www.cnblogs.com/klb561/p/8858122.html 一.基础介绍 核心概念:test case, testsuite, TestLoder,Tex ...

  6. python之unittest框架使用

    一.unittest框架 unittest属于python内置的单元测试框架. 二.unittest框架的核心概念 test case:指测试用例.unittest中提供了一个基本类TestCase, ...

  7. python selenium --unittest 框架

    转自:http://www.cnblogs.com/fnng/p/3300788.html 学习unittest 很好的一个切入点就是从selenium IDE 录制导出脚本.相信不少新手学习sele ...

  8. Unittest 框架之断言,你学会了吗??

    unittest断言 Python在 unittest.TestCase 类中提供了很多断言方法.断言方法检查你认为应该满足的条件是否确实满足.如果该条件确实满足,你对程序行为的假设就得到了确认,你就 ...

  9. 2019.3.23 python的unittest框架与requests

    (明天学测试用例集合及输出测试报告!!!) import unittest import requests import json class Test_get(unittest.TestCase): ...

随机推荐

  1. Ionic国际化解决方案

    1.     核心内容 使用Angular2的国际化(i18n)库:ngx-translate 官网地址:http://www.ngx-translate.com/ GitHub地址:https:// ...

  2. 简单的node爬虫练手,循环中的异步转同步

    简单的node爬虫练手,循环中的异步转同步 转载:https://blog.csdn.net/qq_24504525/article/details/77856989 看到网上一些基于node做的爬虫 ...

  3. 谷歌旗下专业图片编辑Snapseed获重大更新

    谷歌旗下的图片编辑应用Snapseed今天获得重大更新,承诺为用户的手机或者平板带来“精确和卓越控制的专业图片编辑软件”.Android和iOS版本同时获得更新,新增包括镜头模糊.色条对比.更加灵活的 ...

  4. vue项目引入element

    前提工作-安装并配置好以下环境: 1.安装node  2.安装git 1.初始化项目 vue init webpack vue-elementui npm run dev 2.安装element np ...

  5. 解决 ImportError: cannot import name pywrap_tensorflow

    原文:https://aichamp.wordpress.com/2016/11/13/handeling-importerror-cannot-import-name-pywrap_tensorfl ...

  6. thinkPHP3.2.2 数据库对表的操作

    增加:M('表名')->add($data); 删除:M('表名')->delete($id); 更新:M('表名')->save($data); 查询:M('表名')->se ...

  7. Java volatile关键字解惑

    volatile特性 内存可见性:通俗来说就是,线程A对一个volatile变量的修改,对于其它线程来说是可见的,即线程每次获取volatile变量的值都是最新的. volatile的使用场景 通过关 ...

  8. 【Java】得到当前股票信息

    import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; ...

  9. 回归JavaScript基础(六)

    主题:引用类型Date.RegExp的介绍. 上节主要主要介绍了Object.Array引用类型.这节将继续为大家介绍引用类型,并对书中的一些知识点进行总结与归纳,也借此巩固自己对JavaScript ...

  10. eclipse安装python

    在Eclipse中安装pydev插件 启动Eclipse, 点击Help->Install New Software...   在弹出的对话框中,点Add 按钮.  Name中填:Pydev,  ...