【发布时间】:2015-03-14 21:49:02
【问题描述】:
Junit4中有没有办法将一些预初始化的数据(例如您在使用'@RunWith(Suite.class)'注释的类中使用'@ClassRule'初始化的http连接)传递给所有子(即套件)测试类?还有如何保证套件中的类不能单独运行?
例如
class A {
private HttpClient client;
@Test
public void someTest() {
client.execute(...);
...
}
}
@RunWith(Suite.class)
@Suite.SuiteClasses({A.class})
public class Suite {
private static HttpClient client;
@ClassRule
public static ExternalResource resource= new ExternalResource() {
@Override
protected void before() throws Throwable {
client = new DefaultHttpClient();
}
}
谢谢,
稻谷
【问题讨论】:
标签: java junit test-suite