当前位置:网站首页>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()边栏推荐
- IDEA快捷键大全
- 吃透Chisel语言.04.Chisel基础(一)——信号类型和常量
- 2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
- E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
- 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
- 華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
- CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
- Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
- [R language data science]: cross validation and looking back
- OPPO Find N2产品形态首曝:补齐各项短板
猜你喜欢

基于YOLOv1的口罩佩戴检测

Applet live + e-commerce, if you want to be a new retail e-commerce, use it!

Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder

【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结

CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...

MySQL 5 installation and modification free

OpenHarmony应用开发之如何创建DAYU200预览器

China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder

Use the default route as the route to the Internet

吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
随机推荐
WS2818M是CPC8封装,是三通道LED驱动控制专用电路外置IC全彩双信号5V32灯可编程led灯带户外工程
OpenHarmony应用开发之如何创建DAYU200预览器
Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
Basic mode of service mesh
Test evaluation of software testing
205. 同构字符串
392. Judgement subsequence
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
以房抵债能否排除强制执行
xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
【C 题集】of Ⅶ
392. 判断子序列
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
PHP log debugging
go vendor 项目迁移到 mod 项目
MySQL 5 installation and modification free