1 回答
TA贡献1798条经验 获得超7个赞
我找到了使用 '@ClassRule' 并实现 customg 的解决方案TestWatcher。由于在方法starting(Description description)之前被调用,@BeforeClass public static void beforeClass()我可以像这样使用它:
这是我的代码:
public abstract class BaseTest {
@ClassRule
public static CustomTestWatcher classWatcher = new CustomTestWatcher();
private static Map<String, String> testConfig;
private static FakeApplication fakeApplication;
public static class CustomTestWatcher extends TestWatcher {
private String className = BaseTest.class.getSimpleName();
public String getClassName() {
return className;
}
private void setClassName(String className) {
this.className = className;
}
@Override
protected void starting(Description description) {
//This will set className to = FooTest!
setClassName(description.getClassName());
System.out.println("\nStarting test class: " + className);
}
}
@BeforeClass
public static void beforeClass() {
//Here now finally is FooTest!
String className = classWatcher.getClassName();
System.out.println("Creating Test Database and Fake Application for " + className);
...
}
添加回答
举报