JUnit 4中的java,有没有一种方法可以在扩展BlockJUnit4ClassRunner的自定义运行程序中,在all@BeforeClass之前运行一段代码
在扩展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
# 1 楼答案
你能覆盖^{} 吗?BlockJUnit4ClassRunner扩展ParentRunner,但不覆盖
classBlock
(或将其标记为final
),因此您仍有权覆盖它