junit 4 测试运行器
2014-04-10 11:40
441 查看
JUnit 中所有的测试方法都是由测试运行器负责执行。JUnit单元测试提供了一个默认的测试运行器BlockJunit4ClassRunner,但是并没有限制必须使用默认的运行器。
我们可以根据需要定制自己的运行器,只要继承自org.junit.runner.Runner即可。一般情况下,默认测试运行器可以应对绝大多数的单元测试要求。当使用JUnit提供的一些高级特性(如实现参数化测试、实现打包测试或者针对特殊需求定制JUnit测试方式)时,则需要显示地声明测试运行器。如@RunWith(CustomerTestRunner.class)。
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
/**
* @author Chris
*
*/
@RunWith(Suite.class)
@SuiteClasses({JunitExceptionTest.class,Junit4ParameterTest.class,JunitTimeoutTest.class})
public class JUnit4SuiteTest {
@Test
public void allTest(){
assertNotNull(null);
}
}
JUnit 为我们提供了打包测试的功能,将所有需要运行的测试用例集中起来,一次性地运行所有测试用例,大大地方便了我们的测试工作。
通过@RunWith注解指定一个Suite测试运行器,另外通过@SuiteClasses注解将所有需要进行测试的用例打包起来。
我们可以根据需要定制自己的运行器,只要继承自org.junit.runner.Runner即可。一般情况下,默认测试运行器可以应对绝大多数的单元测试要求。当使用JUnit提供的一些高级特性(如实现参数化测试、实现打包测试或者针对特殊需求定制JUnit测试方式)时,则需要显示地声明测试运行器。如@RunWith(CustomerTestRunner.class)。
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
/**
* @author Chris
*
*/
@RunWith(Suite.class)
@SuiteClasses({JunitExceptionTest.class,Junit4ParameterTest.class,JunitTimeoutTest.class})
public class JUnit4SuiteTest {
@Test
public void allTest(){
assertNotNull(null);
}
}
JUnit 为我们提供了打包测试的功能,将所有需要运行的测试用例集中起来,一次性地运行所有测试用例,大大地方便了我们的测试工作。
通过@RunWith注解指定一个Suite测试运行器,另外通过@SuiteClasses注解将所有需要进行测试的用例打包起来。
相关文章推荐
- 第四周的作业
- 弹出层iframe链接设置
- Team Foundation API - 编程访问 WorkItem
- TextView关于xml属性用法(待完善)
- Cracking The Coding Interview 3.2
- NYOJ457大小写互换
- 真机错误
- Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
- ext-basex.js处理的同步请求在Firefox12、谷歌最新版本中不支持(在Firefox11中是支持的)怎么办?(已解答)
- junit 4 参数化测试
- AjaxPro使用说明
- using作用
- 使用.NET FrameWork获取CPU,内存使用率以及磁盘空间
- (转)C#实现MD5加密
- 台式机bios参数说明
- SEH exception with code 0xc0000005 error
- Problem 64 如何设置Linux系统内存回收的阀值?
- junit 4 超时测试
- 四种SQL分页语句
- 我硕士毕业为什么在佳木斯卖米粉d