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

边栏推荐
- 结合案例:Flink框架中的最底层API(ProcessFunction)用法
- OPPO Find N2产品形态首曝:补齐各项短板
- Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
- 英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
- 程序员转方向
- Animation and transition effects
- Gorm 读写分离(转)
- Unity shader learning (3) try to draw a circle
- 美国土安全部部长警告移民“不要踏上危险的旅程”
- 动画与过渡效果
猜你喜欢

基于YOLOv1的口罩佩戴检测

1200. 最小绝对差

Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder

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

sharding key type not supported

Go 语言入门很简单:Go 实现凯撒密码

Automatic filling of database public fields

Unity shader learning (3) try to draw a circle
![[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp](/img/eb/11e5da1c5e897c5f6a18d49125925f.png)
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp

吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
随机推荐
CVPR 2022 | greatly reduce the manual annotation required for zero sample learning, and propose category semantic embedding rich in visual information (source code download)
qt 怎么检测鼠标在不在某个控件上
2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
js中的变量提升和函数提升
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
2022年山东省安全员C证考试题库及在线模拟考试
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
MySQL8版本免安装步骤教程
mac redis安装与使用,连接远程服务器 redis
Byte interview algorithm question
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
Service Mesh的基本模式
忠诚协议是否具有法律效力
吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
Qt如何实现打包,实现EXE分享
Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua
[antd] how to set antd in form There is input in item Get input when gourp Value of each input of gourp
近日小结(非技术文)
MySQL version 8 installation Free Tutorial
ASP. Net core introduction I