当前位置:网站首页>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()边栏推荐
- Test evaluation of software testing
- 如何在 2022 年为 Web 应用程序选择技术堆栈
- Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
- Unity Shader学习(三)试着绘制一个圆
- 好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
- find命令报错: paths must precede expression(转)
- 以房抵债能否排除强制执行
- OPPO Find N2产品形态首曝:补齐各项短板
- 面试拆解:系统上线后Cpu使用率飙升如何排查?
- Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
猜你喜欢

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

分布式BASE理论

.Net之延迟队列

Interview disassembly: how to check the soaring usage of CPU after the system goes online?

. Net delay queue

基于PaddleX的智能零售柜商品识别
![30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)](/img/89/aabf79ca02bf587e93885cadd5f98a.png)
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)

392. 判断子序列

2022年起重机械指挥考试模拟100题模拟考试平台操作

2022危险化学品经营单位主要负责人练习题及模拟考试
随机推荐
以房抵债能否排除强制执行
Interviewer: what is the internal implementation of hash data type in redis?
DGraph: 大规模动态图数据集
硬件基础知识-二极管基础
吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
WS2811 M是三通道LED驱动控制专用电路彩灯带方案开发
Install Trinity and solve error reporting
Byte interview algorithm question
逆向调试入门-PE结构-资源表07/07
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
Can mortgage with housing exclude compulsory execution
Mask wearing detection based on yolov1
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
One of the solutions for unity not recognizing riders
基于STM32+华为云IOT设计的酒驾监控系统
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
近日小结(非技术文)
Test evaluation of software testing