当前位置:网站首页>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 :
边栏推荐
- 嵌入式编程中五个必探的“潜在错误”
- Whether the loyalty agreement has legal effect
- 2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
- xshell/bash/zsh 等终端鼠标滚轮乱码问题(转)
- 吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
- JVM 内存布局详解,图文并茂,写得太好了!
- Basic mode of service mesh
- 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
- 一次 Keepalived 高可用的事故,让我重学了一遍它
- go语言中的文件创建,写入,读取,删除(转)
猜你喜欢
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
sharding key type not supported
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Test evaluation of software testing
JVM memory layout detailed, illustrated, well written!
基于PaddleX的智能零售柜商品识别
Detailed explanation of Fisher information quantity detection countermeasure sample code
【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
Product identification of intelligent retail cabinet based on paddlex
随机推荐
小程序直播 + 电商,想做新零售电商就用它吧!
Worried about "cutting off gas", Germany is revising the energy security law
Install MySQL
JVM memory layout detailed, illustrated, well written!
Distributed base theory
Haobo medical sprint technology innovation board: annual revenue of 260million Yonggang and Shen Zhiqun are the actual controllers
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
. Net delay queue
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
使用默认路由作为指向Internet的路由
CVPR 2022 | greatly reduce the manual annotation required for zero sample learning, and propose category semantic embedding rich in visual information (source code download)
JVM 内存布局详解,图文并茂,写得太好了!
如何在 2022 年为 Web 应用程序选择技术堆栈
Getting started with the go language is simple: go implements the Caesar password
go vendor 项目迁移到 mod 项目
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)