Selenium2+python自动化70-unittest之跳过用例(skip)
前言
当测试用例写完后,有些模块有改动时候,会影响到部分用例的执行,这个时候我们希望暂时跳过这些用例。
或者前面某个功能运行失败了,后面的几个用例是依赖于这个功能的用例,如果第一步就失败了,后面的用例也就没必要去执行了,直接跳过就行,节省用例执行时间。
一、skip装饰器
skip装饰器一共有四个
@
unittest.
skip
(reason)
-
Unconditionally skip the decorated test. reason should describe why the test is being skipped.
翻译:无条件跳过用例,reason是说明原因
@
unittest.
skipIf
(condition, reason)-
Skip the decorated test if condition is true.
翻译:condition为true的时候跳过
@
unittest.
skipUnless
(condition, reason)-
Skip the decorated test unless condition is true.
翻译:condition为False的时候跳过
@
unittest.
expectedFailure
-
Mark the test as an expected failure. If the test fails when run, the test is not counted as a failure.
翻译:断言的时候跳过()
二、skip案例
运行结果:
测试1
测试4
.ssx
----------------------------------------------------------------------
Ran 4 tests in 0.003s
OK (skipped=2, expected failures=1)
三、跳过整个测试类
四、参考代码:
# coding:utf-8
import unittest
class Test(unittest.TestCase):
@unittest.skip(u"无条件跳过此用例")
def test_1(self):
print "测试1"
@unittest.skipIf(True, u"为True的时候跳过")
def test_2(self):
print "测试2"
@unittest.skipUnless(False, u"为False的时候跳过")
def test_3(self):
print "测试3"
@unittest.expectedFailure
def test_4(self):
print "测试4"
self.assertEqual(2, 4, msg=u"判断相等")
if __name__ == "__main__":
unittest.main()
** 作者:上海-悠悠 QQ交流群:588402570**
最新文章
- Hibernate学习笔记2
- 为什么不推崇复杂的ORM
- The service ‘xxx’ configured for WCF is not registered with the Autofac container
- iOS开发——语法篇OC篇&;高级语法精讲
- Java Hibernate 主键生成10大策略
- ubuntu下java和tomcat安装配置
- 大数据测试之hadoop集群配置和测试
- Python入门(一):PTVS写Python程序,调试模式下input()提示文字乱码问题
- Cocos2dx开发之运行与渲染流程分析
- ElasticSearch(二):允许外网连接服务配置
- Numpy float64和Python float是一样的
- (qsort)绝对值排序
- composer ip2city配置
- Java命令学习系列(七)——javap
- Centos7 KDE 桌面Konsole 光标错位解决方法
- PHP 利用文件锁处理高并发
- UIViewController读书笔记
- 10分钟搞定webpack打包
- python之变量的命名规则
- scott权限
热门文章
- html5多媒体Video/Audio
- MVC – 3.EF(Entity Framework)
- Java String class methods
- 使用自己的域名解析 cnblogs 博客
- CentOS 7中Nginx1.9.5编译安装教程systemctl启动
- 接口自动化多层嵌套的json数据处理
- file.listFiles()按文件大小、名称、日期排序方法
- Screen 常用命令+VNC 启动停止命令总结
- 无框架完整搭建安卓app及其服务端(一)
- 搭建samba 共享openstack开发环境