没有调用JUnit testRunStarted方法

时间:2017-08-08 13:04:00

标签: java junit

我想在所有junit测试和一个方法之前运行一个方法。以下链接很好地解释了如何实现RunListener,但我不明白为什么不调用tetRunStarted方法。这是我想使用RunListener的主要原因,但testRunFinished方法正常工作。

http://memorynotfound.com/add-junit-listener-example/

1 个答案:

答案 0 :(得分:0)

在MyRunner类中,应添加显式通知:

public class MyRunner extends BlockJUnit4ClassRunner {
...
@Override
public void run(RunNotifier notifier) {
    notifier.addListener(new JtmRunListener());
    notifier.fireTestRunStarted(getDescription());
    super.run(notifier);
}
...
}