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

边栏推荐
- WS2818M是CPC8封装,是三通道LED驱动控制专用电路外置IC全彩双信号5V32灯可编程led灯带户外工程
- CVPR 2022 | greatly reduce the manual annotation required for zero sample learning, and propose category semantic embedding rich in visual information (source code download)
- 动画与过渡效果
- 近日小结(非技术文)
- js中的变量提升和函数提升
- [antd step pit] antd form cooperates with input Form The height occupied by item is incorrect
- ASP. Net core introduction I
- go vendor 项目迁移到 mod 项目
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
- qt 怎么检测鼠标在不在某个控件上
猜你喜欢

吃透Chisel语言.05.Chisel基础(二)——组合电路与运算符

【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法

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

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

華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東

面试拆解:系统上线后Cpu使用率飙升如何排查?

Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million

392. Judgement subsequence

博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
![30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)](/img/89/aabf79ca02bf587e93885cadd5f98a.png)
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
随机推荐
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
Worried about "cutting off gas", Germany is revising the energy security law
MySQL version 8 installation Free Tutorial
1200. 最小绝对差
基于YOLOv1的口罩佩戴检测
做事的真正意义和目的,真正想得到什么
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
2022 practice questions and mock exams for the main principals of hazardous chemical business units
奇妙秘境 码蹄集
Interviewer: what is the internal implementation of hash data type in redis?
MySQL5免安装修改
吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
OPPO Find N2产品形态首曝:补齐各项短板
Dgraph: large scale dynamic graph dataset
Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
2022G3锅炉水处理考试题模拟考试题库及模拟考试
程序员转方向
Whether the loyalty agreement has legal effect
[R language data science]: cross validation and looking back
Qt如何实现打包,实现EXE分享