当前位置:网站首页>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 :

边栏推荐
- MongoDB常用28条查询语句(转)
- 担心“断气” 德国正修改《能源安全法》
- 如何在 2022 年为 Web 应用程序选择技术堆栈
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- Whether the loyalty agreement has legal effect
- Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
- php 日志调试
- One of the solutions for unity not recognizing riders
- 程序员转方向
- CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
猜你喜欢

吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest

博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等

如何在 2022 年为 Web 应用程序选择技术堆栈

Product identification of intelligent retail cabinet based on paddlex

Install MySQL

Unittest框架中引入TestFixture

英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿

华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东

吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器

CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
随机推荐
【R语言数据科学】:交叉验证再回首
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
Whether the loyalty agreement has legal effect
mac redis安装与使用,连接远程服务器 redis
Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
做事的真正意义和目的,真正想得到什么
WS2818M是CPC8封装,是三通道LED驱动控制专用电路外置IC全彩双信号5V32灯可编程led灯带户外工程
Introduction to reverse debugging PE structure resource table 07/07
国内酒店交易DDD应用与实践——代码篇
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
使用默认路由作为指向Internet的路由
Install Trinity and solve error reporting
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
MySQL5免安装修改
Test evaluation of software testing
Secretary of Homeland Security of the United States: domestic violent extremism is one of the biggest terrorist threats facing the United States at present