当前位置:网站首页>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()
边栏推荐
- 【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
- MySQL5免安装修改
- China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
- How to choose a technology stack for web applications in 2022
- Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
- 1200. 最小绝对差
- 2022G3锅炉水处理考试题模拟考试题库及模拟考试
- Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
- 华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
- 基于PaddleX的智能零售柜商品识别
猜你喜欢
苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?
ASP. Net core introduction I
Huahao Zhongtian rushes to the scientific and Technological Innovation Board: the annual loss is 280million, and it is proposed to raise 1.5 billion. Beida pharmaceutical is a shareholder
使用默认路由作为指向Internet的路由
MySQL5免安装修改
205. 同构字符串
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
硬件基础知识-二极管基础
MySQL8版本免安装步骤教程
随机推荐
程序员的焦虑
Dgraph: large scale dynamic graph dataset
sharding key type not supported
Can mortgage with housing exclude compulsory execution
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
Fs4056 800mA charging IC domestic fast charging power IC
吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
软件测试之测试评估
Install MySQL
硬件基础知识-二极管基础
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
Read excel table data
MySQL5免安装修改
Source code compilation and installation of MySQL
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
[antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
JVM series - stack and heap, method area day1-2
吃透Chisel语言.03.写给Verilog转Chisel的开发者(没有Verilog基础也可以看看)
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc