当前位置:网站首页>Unittest框架之断言
Unittest框架之断言
2022-07-04 12:49:00 【大田测试录】
1、先认识Unittest断言
1)断言就是判断实际结果与预期结果是否一致;
2)虽然 Python 中也有自带的断言,但是最好还是使用Unittest自己的断言,比较好用;
3)unittest断言是在TestCase中实现的,需要在继承TestCase后才能使用断言;
2、常见断言方法
assertEqual(a,b):检查a和b是否相等
assertTrue(a):检查a是不是为true
assertIs(a,b):检查a和b是不是完全一样(assert is)
assertIsNone(a):检查a是不是None
assertIn(a,b):检查a是不是b的子集
assertIsInstance(a,b):检查a、b两个对象实例类型是否相同
3、例子
unittest_assert_demo.py
# 断言
import unittest
class AssertDemo(unittest.TestCase):
def setUp(self):
self.l1, self.l2 = [1, 2], [1, 2]
self.a, self.b = 1, 1
def test01_assertEqual(self):
self.assertEqual(self.a, self.b) # a和b相等
def test02_assertIs(self):
self.assertIs(self.l1, self.l2) # l1和l2不相同
self.assertIs(self.a, self.b) # a和b相同
def test03_assertTrue(self):
self.assertTrue(self.a) # 1 是true
self.assertTrue(0) # 0 是false
def test04_assertIsNone(self):
self.assertIsNone(self.b) # 1 不是 None
self.assertIsNone(None) # None 是 None
def test05_assertIn(self):
self.assertIn(self.l1, self.l2) # l1 不是l2的子集
def test06_assertIsInstance(self):
self.assertIsInstance(self.a, int) # a是int整型
self.assertIsInstance(self.l1, list) # l1是list列表型
if __name__ == '__main__':
unittest.main()
边栏推荐
- The only core indicator of high-quality software architecture
- Interviewer: what is the internal implementation of hash data type in redis?
- Node の MongoDB 安装
- OPPO Find N2产品形态首曝:补齐各项短板
- js中的变量提升和函数提升
- 205. 同构字符串
- BLOB,TEXT GEOMETRY or JSON column 'xxx' can't have a default value query 问题
- qt 怎么检测鼠标在不在某个控件上
- Automatic filling of database public fields
- Getting started with microservices
猜你喜欢
Oracle 被 Ventana Research 评为数字创新奖总冠军
HAProxy高可用解决方案
392. 判断子序列
【R语言数据科学】:交叉验证再回首
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
源码编译安装MySQL
2022年山东省安全员C证考试题库及在线模拟考试
Five "potential errors" in embedded programming
markdown 语法之字体标红
MySQL 45 lecture - learn the actual combat notes of MySQL in Geek time 45 lecture - 06 | global lock and table lock_ Why are there so many obstacles in adding a field to the table
随机推荐
【C 题集】of Ⅶ
XML入门二
C foundation in-depth learning II
OPPO Find N2产品形态首曝:补齐各项短板
C语言图书租赁管理系统
Oracle was named the champion of Digital Innovation Award by Ventana research
Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
面试拆解:系统上线后Cpu使用率飙升如何排查?
学习项目是自己找的,成长机会是自己创造的
CommVault cooperates with Oracle to provide metallic data management as a service on Oracle cloud
Getting started with microservices
How to choose a technology stack for web applications in 2022
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
2022危险化学品经营单位主要负责人练习题及模拟考试
嵌入式编程中五个必探的“潜在错误”
Node mongodb installation
基于链表管理的单片机轮询程序框架
mac redis安装与使用,连接远程服务器 redis
Go 语言入门很简单:Go 实现凯撒密码