当前位置:网站首页>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 :
边栏推荐
- Automatic filling of database public fields
- 2022 practice questions and mock exams for the main principals of hazardous chemical business units
- IDEA快捷键大全
- Understand chisel language thoroughly 11. Chisel project construction, operation and test (III) -- scalatest of chisel test
- 小程序直播 + 电商,想做新零售电商就用它吧!
- Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present
- JVM 内存布局详解,图文并茂,写得太好了!
- JVM series - stack and heap, method area day1-2
- Worried about "cutting off gas", Germany is revising the energy security law
- 近日小结(非技术文)
猜你喜欢
OpenHarmony应用开发之如何创建DAYU200预览器
SCM polling program framework based on linked list management
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
Hardware Basics - diode Basics
DGraph: 大规模动态图数据集
分布式BASE理论
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
Install Trinity and solve error reporting
Use the default route as the route to the Internet
硬件基础知识-二极管基础
随机推荐
Automatic filling of database public fields
Byte interview algorithm question
2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
Dgraph: large scale dynamic graph dataset
go vendor 项目迁移到 mod 项目
Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder
Unity shader learning (3) try to draw a circle
sharding key type not supported
面试拆解:系统上线后Cpu使用率飙升如何排查?
吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
How to choose a technology stack for web applications in 2022
自主工业软件的创新与发展
吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符
Go 语言入门很简单:Go 实现凯撒密码
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
2022年起重机械指挥考试模拟100题模拟考试平台操作
Openharmony application development how to create dayu200 previewer
1200. 最小绝对差
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结