【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上 ...
随机推荐
- [转]Magento2开发教程 - 如何向数据库添加新表
本文转自:https://www.cnblogs.com/xz-src/p/6920365.html Magento 2具有特殊的机制,允许你创建数据库表,修改现有的,甚至添加一些数据到他们(如安装数 ...
- easyui datagrid 动态改变行背景色
/*根据查询条件查询调度单列表*/ function InitGrid(queryData) { $("#dg").datagrid({ loadMsg: "数据加载中, ...
- wei
<!--PageEndHtml Block Begin--> JAVASCRIPT: <script charset="Shift_JIS" src=&q ...
- Dijkstra和Prim算法的区别
Dijkstra和Prim算法的区别 1.先说说prim算法的思想: 众所周知,prim算法是一个最小生成树算法,它运用的是贪心原理(在这里不再证明),设置两个点集合,一个集合为要求的生成树的点集合A ...
- Mybatis的枚举处理器
Mybatis有两个默认枚举处理器 EnumOrdinalTypeHandler EnumTypeHandler 自定义枚举 EnumOrdinalTypeHandler 这个处理器负责将pojo里面 ...
- 1.String、StringBuffer与StringBuilder之间区别
1.三者在执行速度方面的比较:StringBuilder > StringBuffer > String 2.String <(StringBuffer,StringBuild ...
- OSGI企业应用开发(十二)OSGI Web应用开发(一)
前面文章中介绍了如何在OSGI应用中整合Spring和Mybatis框架,本篇文章开始介绍如何使用OSGI技术开发Web应用.对于传统的Java EE应用,应用中涉及到的Web元素无非就是Servle ...
- Windows7安装 nginx+php 后访问.php文件出现 “No input file specified.” 的解决办法
在Windows7上安装了Nginx+PHP,参考教程为 https://www.cnblogs.com/anlia/p/5916758.html 启动 nginx 后,在浏览器中输入localhos ...
- Android之在linux终端执行shell脚本直接打印当前运行app的日志
1.问题 我们一般很多时候会需要在ubuntu终端上打印当前运行app的日志,我们一般常见的做法是 1).获取包名 打开当前运行的app,然后输入如下命令,然后在第一行TASK后面的就可以看到包名 a ...
- Java web 开发填坑记 2 -如何正确的创建一个Java Web 项目
转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/72566261 本文出自[赵彦军的博客] Java web 开发填坑记 1-如何正确 ...