当前位置:网站首页>Assertion of unittest framework
Assertion of unittest framework
2022-07-04 14:09:00 【Field test record】
1、 Meet first Unittest Assertion
1) Assertion is to judge whether the actual result is consistent with the expected result ;
2) although Python There are also self-contained assertions , But it's better to use Unittest Own assertion , Work well ;
3)unittest The assertion is that TestCase Implemented in , Need to inherit TestCase Before using assertions ;
2、 Common assertion methods
assertEqual(a,b): Check a and b Whether it is equal or not
assertTrue(a): Check a Is it for true
assertIs(a,b): Check a and b Is it exactly the same (assert is)
assertIsNone(a): Check a Is it right? None
assertIn(a,b): Check a Is it right? b Subset
assertIsInstance(a,b): Check a、b Whether the two object instance types are the same
3、 Example
unittest_assert_demo.py
# Assertion
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 and b equal
def test02_assertIs(self):
self.assertIs(self.l1, self.l2) # l1 and l2 inequality
self.assertIs(self.a, self.b) # a and b identical
def test03_assertTrue(self):
self.assertTrue(self.a) # 1 yes true
self.assertTrue(0) # 0 yes false
def test04_assertIsNone(self):
self.assertIsNone(self.b) # 1 No None
self.assertIsNone(None) # None yes None
def test05_assertIn(self):
self.assertIn(self.l1, self.l2) # l1 No l2 Subset
def test06_assertIsInstance(self):
self.assertIsInstance(self.a, int) # a yes int integer
self.assertIsInstance(self.l1, list) # l1 yes list List
if __name__ == '__main__':
unittest.main()边栏推荐
- 1200. Minimum absolute difference
- Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua
- . Net delay queue
- Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
- 吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
- IP 实验室月复盘 · 第 5 期
- One of the solutions for unity not recognizing riders
- MySQL5免安装修改
- 【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
猜你喜欢

Product identification of intelligent retail cabinet based on paddlex

DGraph: 大规模动态图数据集

Interviewer: what is the internal implementation of hash data type in redis?

Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc

一次 Keepalived 高可用的事故,让我重学了一遍它

MySQL 5 installation and modification free

Automatic filling of database public fields

苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?

近日小结(非技术文)

嵌入式编程中五个必探的“潜在错误”
随机推荐
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
读取 Excel 表数据
sharding key type not supported
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
. Net delay queue
Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
Programmer anxiety
Fs4056 800mA charging IC domestic fast charging power IC
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
Understanding and difference between viewbinding and databinding
Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
Summary of recent days (non-technical article)
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
【R语言数据科学】:交叉验证再回首
程序员转方向
嵌入式编程中五个必探的“潜在错误”
Interview disassembly: how to check the soaring usage of CPU after the system goes online?