JUnit4中的测试套件
测试套件
JUnit3.8中,用测试套件同时运行多个测试类(http://www.cnblogs.com/mengdd/archive/2013/04/07/3006265.html)。
在JUnit4中也有类似功能,只不过是用注解来实现的。
Suite类的文档
public class Suite
extends org.junit.internal.runners.CompositeRunnerUsing
Suite as a runner allows you to manually build a suite containing tests from many classes.
It is the JUnit 4 equivalent of the JUnit 3.8.x static Test suite() method.
To use it, annotate a class with @RunWith(Suite.class) and @SuiteClasses(TestClass1.class, ...).
When you run this class, it will run all the tests in all the suite classes.
程序实例
写一个类TestAll,然后让其运行CalculatorTest和ParametersTest中的测试:
package com.mengdd.junit4; import org.junit.runner.RunWith;
import org.junit.runners.Suite; @RunWith(Suite.class)
// 指定运行器
@Suite.SuiteClasses({ CalculatorTest.class, ParametersTest.class })
// 指定要测试的类
public class TestAll
{ }
另,在一个套件中也可包含另一个套件类,比如:
再写一个类TestAll2,其中指定的类是上面的TestAll:
package com.mengdd.junit4; import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class)
@SuiteClasses(TestAll.class)
// 除了指定类,也可以指定套件类
public class TestAll2
{ }
总结:
在JUnit4中,如果想要同时运行多个测试类,需要使用两个注解:
@RunWith(Suite.class)指定使用Suite运行器来运行测试;
@SuiteClasses(ClassName.class)指定运行哪些测试类。测试类可以指定为Suite,这样JUnit会继续再去寻找里面的测试类,一直找到能够执行的Test Case并执行之。
参考资料
圣思园张龙老师视频教程。
JUnit4 chm格式文档网盘下载链接:
JUnit 4.0:http://pan.baidu.com/share/link?shareid=539345&uk=2701745266
JUnit4中的测试套件的更多相关文章
- Robot Framework(四)创建测试套件
2.3.1测试用例文件 Robot Framework测试用例是使用测试用例文件中的测试用例表创建的.这样的文件会自动从它包含的所有测试用例中创建一个测试套件.可以有多少测试用例没有上限,但建议少于1 ...
- Junit4进行参数化测试
@RunWith, 当类被@RunWith注解修饰,或者类继承了一个被该注解修饰的类,JUnit将会使用这个注解所指明的运行器(runner)来运行测试,而不是JUnit默认的运行器. 要进行参数化测 ...
- Junit4学习(五)Junit4测试套件
一,背景 1,随着开发规模的深入和扩大,项目或越来越大,相应的我们的测试类也会越来越多:那么就带来一个问题,假如测试类很多,就需要多次运行,造成测试的成本增加:此时就可以使用junit批量运行测试类的 ...
- 『心善渊』Selenium3.0基础 — 28、unittest中测试套件的使用
目录 1.测试套件的作用 2.使用测试套件 (1)入门示例 (2)根据不同的条件加载测试用例(了解) (3)常用方式(推荐) 1.测试套件的作用 在我们实际工作,使用unittest框架会有两个问题: ...
- Spring Test+JUnit4整合使用测试ZZJ_淘淘商城项目:day01(RESTful Web Service)
针对整合的Dao层与Service层,在做spring与通用Mapper和分页插件相关测试时比较麻烦.如果只用JUnit测试,需要每次Test方法里初始化一下applicationContext,效率 ...
- 使用Spring+Junit4.4进行测试(使用注解)
http://nottiansyf.iteye.com/blog/345819 使用Junit4.4测试 在类上的配置Annotation @RunWith(SpringJUnit4ClassRunn ...
- 用Spring+Junit4.4进行测试(使用注解)
http://nottiansyf.iteye.com/blog/345819 使用Junit4.4测试 在类上的配置Annotation @RunWith(SpringJUnit4ClassRunn ...
- selenium测试套件
1.测试套件测试套件,简单理解就是讲多个用例,装在一个容器里来同时执行完成. 2.测试套件分析 #coding=utf-8 import unittestimport BaiDuSearch,BaiD ...
- 【转】兼容性测试套件(CTS)框架用户手册
原文网址:http://blog.sina.com.cn/s/blog_416166e90102v6bi.html 兼容性测试套件(CTS)框架用户手册 1.为什么需要兼容性测试(以下称CTS)? 2 ...
随机推荐
- oracle卸载Oracle Clusterware(转载)
1.脚本自动删除 切换到root用户 $Su – root #cd $ORA_CRS_HOME/install 1.执行rootdelete.sh脚本 # ./rootdelete.sh 2.执行ro ...
- [转]CSS目标伪类E:target
CSS3 target 伪类不得不说那些事儿(纯CSS实现tab切换) 是不是觉得target有点眼熟?! 今天要讲的不是HTML的<a>标签里面有个target属性. target伪类是 ...
- 页面全部加载完毕和页面dom树加载完毕
dom树加载完毕 $(document).ready()//原生写法document.ready = function (callback) { ///兼容FF,Google ...
- DTO学习系列之AutoMapper(四)
本篇目录: Mapping Inheritance-映射继承 Queryable Extensions (LINQ)-扩展查询表达式 Configuration-配置 Conditional Mapp ...
- BZOJ4195 NOI2015 程序自动分析
4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Description 在实现程序自动分析的过程中,常常需要判定一些约束条件 ...
- ubuntu中安装eclipse
1.下载eclipse安装包 http://mirror.neu.edu.cn/eclipse/technology/epp/downloads/release/kepler/SR2/eclipse- ...
- UIP协议栈
UIP协议栈笔记 http://blog.chinaunix.net/uid-23247944-id-2974928.html
- JavaIO学习总结一
Java IO 输入输出 一.概念 Java中输入输出操作是以流的方式进行的,流是Java内存中的一组有序数据序列.Java将数据从源(文件.内存.控制台.网络)读入到内存中,形成了流,然后将这些流还 ...
- html 作业1
<body bgcolor="#000000" topmargin="200px" leftmargin="200px" text=& ...
- unity3D对象的显示和隐藏
SetActive/active/SetActiveRecursively 后两者比较旧,现在通常用第一个SetActive 必须先new一个gameobject对象用于实例化,然后再设置其activ ...