您的位置:首页 > 其它

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注解将所有需要进行测试的用例打包起来。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: