Java 在JUnit4中,是否有一种方法可以在扩展BlockJUnit4ClassRunner的自定义运行程序中的all@BeforeClass之前运行一段代码
在扩展Java 在JUnit4中,是否有一种方法可以在扩展BlockJUnit4ClassRunner的自定义运行程序中的all@BeforeClass之前运行一段代码,java,junit,junit4,Java,Junit,Junit4,在扩展BlockJUnit4ClassRunner的自定义运行程序中调用@BeforeClass之前,我想运行一些方法 我该怎么做 当重写runChild方法时,我发现它按测试方法运行 protected void runChild(FrameworkMethod child, RunNotifier notifier) { System.out.println("a"); super.runChild(child, notifier); System.out.print
BlockJUnit4ClassRunner
的自定义运行程序中调用@BeforeClass
之前,我想运行一些方法
我该怎么做
当重写runChild
方法时,我发现它按测试方法运行
protected void runChild(FrameworkMethod child, RunNotifier notifier) {
System.out.println("a");
super.runChild(child, notifier);
System.out.println("b");
}
产生以下输出:
a
test here
b
a
test here
b
你能超越吗?BlockJUnit4ClassRunner扩展ParentRunner,但不覆盖classBlock
(或将其标记为final
),因此您仍有权覆盖它
/**
* Constructs a {@code Statement} to run all of the tests in the test class.
* Override to add pre-/post-processing.
* [snip]
*/
protected Statement classBlock(final RunNotifier notifier) { /* ... */ }