Python的unittest框架的断言总结
常用的断言方法如下:
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框架的断言总结的更多相关文章
- selenium + python自动化测试unittest框架学习(一)selenium原理及应用
unittest框架的学习得益于虫师的<selenium+python自动化实践>这一书,该书讲得很详细,大家可以去看下,我也只学到一点点用于工作中,闲暇时记录下自己所学才能更加印象深刻. ...
- python之unittest框架实现接口测试实例
python之unittest框架实现接口测试实例 接口测试的方法有很多种,具体到工具有postman,jmeter,fiddler等,但是工具的局限性是测试数据的组织较差,接口的返回工具的判断有限, ...
- selenium + python自动化测试unittest框架学习(二)
1.unittest单元测试框架文件结构 unittest是python单元测试框架之一,unittest测试框架的主要文件结构: File >report >all_case.py &g ...
- python的unittest框架中的assert断言
unittest框架自带断言,如果想用assert断言,一定要引入unittest.TestCase框架才行,不然不会自动识别assert断言
- selenium自动化测试、Python单元测试unittest框架以及测试报告和日志输出
部分内容来自:https://www.cnblogs.com/klb561/p/8858122.html 一.基础介绍 核心概念:test case, testsuite, TestLoder,Tex ...
- python之unittest框架使用
一.unittest框架 unittest属于python内置的单元测试框架. 二.unittest框架的核心概念 test case:指测试用例.unittest中提供了一个基本类TestCase, ...
- python selenium --unittest 框架
转自:http://www.cnblogs.com/fnng/p/3300788.html 学习unittest 很好的一个切入点就是从selenium IDE 录制导出脚本.相信不少新手学习sele ...
- Unittest 框架之断言,你学会了吗??
unittest断言 Python在 unittest.TestCase 类中提供了很多断言方法.断言方法检查你认为应该满足的条件是否确实满足.如果该条件确实满足,你对程序行为的假设就得到了确认,你就 ...
- 2019.3.23 python的unittest框架与requests
(明天学测试用例集合及输出测试报告!!!) import unittest import requests import json class Test_get(unittest.TestCase): ...
随机推荐
- nginx重启报错:nginx: [error] invalid PID number "" in "/run/nginx.pid"
问题描述:执行 nginx -t 是OK的,然而在执行 nginx -s reload 的时候报错 nginx: [error] invalid PID number “” in “/run/ngin ...
- 2 字节的 UTF-8 序列的字节 2 无效 解决方法
2 字节的 UTF-8 序列的字节 2 无效 解决方法: 用记事本打开xml文件,另存为 编码 选择 UTF-8,保存替换掉之前的文件,解决问题
- 009.在C#.NET中使用Froms验证
原文:https://support.microsoft.com/en-us/kb/301240 (Aty表示本人) 这篇文章演示如何通过数据库,实现Froms验证 必需 Mircosoft Visu ...
- HTML5的audio在手机网页上无法自动加载/播放音乐,能否实现该功能?
在IOS中第一次调用play方法播放音频会被阻止,必须得等用户有交互动作,比如touchstart,click后才能正常调用,在微信中可以通过监听WeixinJSBridgeReady事件来提前播放一 ...
- BZOJ3524: [Poi2014]Couriers(主席树)
题意 题目链接 Sol 严格众数只会出现一次,那么建出主席树,维护子树siz,直接在树上二分即可 #include<bits/stdc++.h> #define LL long long ...
- phoenix使用vue
phoenix使用vue mix phoenix.new ass2 Fetch and install dependencies? [Yn] y 修改 package.json { "rep ...
- 【webpack】从零开始学webpack
背景:目前公司的项目全是用vue写的,建项目的话使用的是用vue-cli直接配置好的webpack,进行打包.现在我就是想实现自己写一个类似vue-cli的架子 一.安装全局依赖 npm instal ...
- OpenGL学习--开发环境
1. VS2017 Professional安装 1.1. 下载 mu_visual_studio_professional_2017_x86_x64_10049787.exe 1.2. 双击开始安装 ...
- FineReport中如何用JavaScript自定义地图标签
在日常使用地图过程中,通常会遇到地图标签,提示点等显示不满足我们的需求,需要进行JavaScript代码编写. 例如:在使用地图过程中,会发现很多地名显示的位置偏离.这时候就需要使用JavaScrip ...
- solidity 语法学习
基于 cryptozombies.io ZombieFactory pragma solidity ^0.4.19; contract ZombieFactory { // 事件, web3.js 可 ...