当前位置:网站首页>Introducing testfixture into unittest framework
Introducing testfixture into unittest framework
2022-07-04 14:09:00 【Field test record】
TestFixture yes Unittest Firmware in the frame , Write it in the class of the test case to be run , Used as the class method of this class .
1、4 There are four common methods :setUp(),tearDown(),setUpClass(),tearDownClass()
2、4 Operation rules of common methods :
setUp(): Functions that will run before running test cases , Used to set configuration information 、 Static attribute
setUpClass(): Need and @classmethod The decorator is used together , After instantiating the class , Methods that will run automatically , Mainly used for instantiating classes 、 Set some environment variables, such as database connection configuration
Use unittest.main() Method will run first setUpClass() Procedure in method
tearDown(): After running a test case , Will run , The function is to destroy the data between each test case 、 Release resources 、 Restore data
tearDownClass(): After all the test cases in the class are run , Methods that will run automatically , The function is to destroy class level resources 、 Restore data
3、 The following figure shows the sequence of running one test case at a time , cycle
4、 Example
test_Fixture_demo.py
# Examples demonstrate fixture Case study
import unittest
# Test class
class SumDemo:
def plus(self, x, y):
return x + y
# establish unittest Test class
class TestSum(unittest.TestCase):
add = None
# Write test build
def setUp(self):
self.x = 1
self.y = 1
print(" It's running setUp")
@classmethod
def setUpClass(cls):
# Instantiation SumDemo
cls.add = SumDemo()
print(" It's running setUpClass")
def tearDown(self):
del self.x
del self.y
print(" It's running tearDown")
@classmethod
def tearDownClass(cls):
del cls.add
print(" It's running teardownClass")
def test_01(self):
result = self.add.plus(2, 3)
print(result)
def test_02(self):
result = self.add.plus(3, 3)
print(result)
Running results :
边栏推荐
- Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
- Interview disassembly: how to check the soaring usage of CPU after the system goes online?
- 逆向调试入门-PE结构-资源表07/07
- 吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
- 吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
- 程序员转方向
- IDEA快捷键大全
- Animation and transition effects
- Openharmony application development how to create dayu200 previewer
- Programmer anxiety
猜你喜欢
【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
小程序直播 + 电商,想做新零售电商就用它吧!
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
分布式BASE理论
sharding key type not supported
Distributed base theory
ASP. Net core introduction I
Five "potential errors" in embedded programming
结合案例:Flink框架中的最底层API(ProcessFunction)用法
OpenHarmony应用开发之如何创建DAYU200预览器
随机推荐
Worried about "cutting off gas", Germany is revising the energy security law
【C 题集】of Ⅶ
Openharmony application development how to create dayu200 previewer
China Post technology rushes to the scientific innovation board: the annual revenue is 2.058 billion, and the postal group is the major shareholder
SCM polling program framework based on linked list management
IP 实验室月复盘 · 第 5 期
DGraph: 大规模动态图数据集
392. 判断子序列
结合案例:Flink框架中的最底层API(ProcessFunction)用法
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
Understand chisel language thoroughly 03. Write to the developer of Verilog to chisel (you can also see it without Verilog Foundation)
国内酒店交易DDD应用与实践——代码篇
博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
Getting started with the go language is simple: go implements the Caesar password
Gorm 读写分离(转)
基于STM32+华为云IOT设计的酒驾监控系统
qt 怎么检测鼠标在不在某个控件上
Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
Five "potential errors" in embedded programming