【Python】【unittest】unittest测试框架中setup,teardown与setupclass,teardownclass的区别
# -*- coding:utf-8 -*-
import unittest def runTest(testcaseclass,testcase=[]):
suite = unittest.TestSuite()
for case in testcase:
suite.addTest(testcaseclass(case))
unittest.TextTestRunner().run(suite) class test(unittest.TestCase): def setUp(self):
print 'This is the setup msg' def tearDown(self):
print 'This is the teardown msg'
@classmethod
def setUpClass(cls):
print 'this is the setupclass msg' @classmethod
def tearDownClass(cls):
print 'this is the teardownclass msg' def test1(self):
print 'This is the first testcase' def test2(self):
print 'This is the second testcase' def test3(self):
print 'This is the third testcase' runTest(test,['test2','test3','test1']) 输出如下:
C:\Python27\python.exe "E:/Project/A3A 8 4G/13.py"
... ---------------------------------------------------------------------- this is the setupclass msg
This is the setup msg
This is the second testcase This is the teardown msg This is the setup msg
This is the third testcase
This is the teardown msg
This is the setup msg
This is the first testcase
This is the teardown msg
this is the teardownclass msg Ran 3 tests in 0.000s OK Process finished with exit code 0
总结:
1、setup()和teardown()两个函数在每条测试用例执行时都会进行重复执行一次,该场景针对那些测试用例间有相互影响的场景,才需要在每执行一条新用例时进行一次初使化,执行完毕后再清空所有配置
2、setupclass(cls)和teardownclass(cls)两个函数在一个用例集合执行前只会执行一次,然后再所有用例执行完成后再清空所有配置,此种用法主要用在用例之间相互没有什么影响的场景
【Python】【unittest】unittest测试框架中setup,teardown与setupclass,teardownclass的区别的更多相关文章
- selenium中的setUp,tearDown与setUpClass,tearDownClass的区别
def setUpClass(cls): cls.driver = webdriver.Chrome() cls.driver.maximize_window() def setUp(self): s ...
- Python的Django REST框架中的序列化及请求和返回
Python的Django REST框架中的序列化及请求和返回 序列化Serialization 1. 设置一个新的环境 在我们开始之前, 我们首先使用virtualenv要创建一个新的虚拟环境,以使 ...
- selenium 测试框架中使用grid
之前的测试框架:http://www.cnblogs.com/tobecrazy/p/4553444.html 配合Jenkins可持续集成:http://www.cnblogs.com/tobecr ...
- hibernate validate验证框架中@NotEmpty、@NotbBank、@NotNull的区别
Hibernate Validator验证框架中@NotEmpty.@NotBlank.@NotNull 的区别 Hibernate Validator验证框架中@NotEmpty.@NotBlank ...
- python unittest自动测试框架
编写函数或者类时进行测试,确保代码正常工作 python unittest 模块提供了代码测试工具.按照定义测试包括两部分:管理测试依赖库的代码(称为‘固件’)和测试本身. 单元测试用于核实函数的某 ...
- Selenium 4 Python的最佳测试框架
随着Python语言的使用越来越流行,基于Python的测试自动化框架也越来越流行.在项目选择最佳框架时,开发人员和测试人员会有些无法下手.做出选择是应该判断很多事情,框架的脚本质量,测试用例的简单性 ...
- Pytest单元测试框架之setup/teardown模块示例操作
"""模块级(setup_module/teardown_module)开始于模块始末,全局的函数级(setup_function/teardown_function)只 ...
- 在测试框架中使用Log4J 2
之前的测试框架:http://www.cnblogs.com/tobecrazy/p/4553444.html 配合Jenkins可持续集成:http://www.cnblogs.com/tobecr ...
- Hibernate Validator验证框架中@NotEmpty、@NotBlank、@NotNull 的区别
Hibernate Validator验证框架中@NotEmpty.@NotBlank.@NotNull的主要使用情况 @NotEmpty 用在集合类上面 @NotBlank 用在String上 ...
随机推荐
- #if _MSC_VER > 1000 #pragma once #endif 含义
前提:MFC应用程序中,MainFrm 类头文件 MainFrm.h 中#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000解释 ...
- 常用的7个SQl优化技巧
作为程序员经常和数据库打交道的时候还是非常频繁的,掌握住一些Sql的优化技巧还是非常有必要的.下面列出一些常用的SQl优化技巧,感兴趣的朋友可以了解一下. 1.注意通配符中Like的使用 以下写法会造 ...
- Java - Stack源码解析
Java提高篇(三一)-----Stack 在Java中Stack类表示后进先出(LIFO)的对象堆栈.栈是一种非常常见的数据结构,它采用典型的先进后出的操作方式完成的.每一个栈都包含一个栈顶,每次出 ...
- HDU6113
度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 【转】android系统常用URI
android系统管理联系人的URI如下:ContactsContract.Contacts.CONTENT_URI 管理联系人的UriContactsContract.CommonDataKinds ...
- js实现分享到QQ
js代码 <script src="http://connect.qq.com/widget/loader/loader.js" widget="shareqq&q ...
- 设计模式原则(7)--Composition&AggregationPrinciple(CARP)--合成&聚合复用原则
作者QQ:1095737364 QQ群:123300273 欢迎加入! 1.定义: 要尽量使用合成和聚合,尽量不要使用继承. 2.使用场景: 要正确的选择合成/复用和继承,必须透彻地理 ...
- CSS3 鼠标划上图片放大
td img{transition: all 1s}/*鼠标划上,图片1s全部显示完成*/ td img:hover{ transform: scale(5) translateX(50%) tran ...
- css3统一元素的宽和高
通常我们设置元素的宽和高样式经常会出现一些问题,比如以下css的设置: 比如以下的代码: <!DOCTYPE html> <html> <head> <met ...
- centos7下采用Nginx+uwsgi来部署django
之前写过采用Apache和mod_wsgi部署django,因为项目需要,并且想比较一下Nginx和Apache的性能,尝试采用Nginx+uwsgi的模式来部署django. 1.安装uwsgi以及 ...