当前位置:网站首页>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()
边栏推荐
- 一次 Keepalived 高可用的事故,让我重学了一遍它
- 【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
- OPPO Find N2产品形态首曝:补齐各项短板
- 安装Mysql
- [C question set] of VII
- Animation and transition effects
- 易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
- 30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
- 面试拆解:系统上线后Cpu使用率飙升如何排查?
- 30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
猜你喜欢
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
Interviewer: what is the internal implementation of hash data type in redis?
国内酒店交易DDD应用与实践——代码篇
Animation and transition effects
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
sharding key type not supported
Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
【R语言数据科学】:交叉验证再回首
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
Unity shader learning (3) try to draw a circle
随机推荐
WS2811 M是三通道LED驱动控制专用电路彩灯带方案开发
做事的真正意义和目的,真正想得到什么
Animation and transition effects
OpenHarmony应用开发之如何创建DAYU200预览器
C language staff management system
逆向调试入门-PE结构-资源表07/07
Mask wearing detection based on yolov1
Unittest中的TestSuite和TestRunner
Use the default route as the route to the Internet
C language programming topic reference
Product identification of intelligent retail cabinet based on paddlex
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
2022年山东省安全员C证考试题库及在线模拟考试
【C 题集】of Ⅶ
软件测试之测试评估
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
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
Haproxy high availability solution
吃透Chisel语言.04.Chisel基础(一)——信号类型和常量