【发布时间】:2013-10-23 21:10:53
【问题描述】:
我正在使用 JUnit,我有这个想法,我想实现它。 我想编写一个运行器,它将每个测试的结果记录到一个 excel 或文本文件中,以便我可以将它附加到我的报告中。 我需要学习什么才能开始
【问题讨论】:
标签: junit4
我正在使用 JUnit,我有这个想法,我想实现它。 我想编写一个运行器,它将每个测试的结果记录到一个 excel 或文本文件中,以便我可以将它附加到我的报告中。 我需要学习什么才能开始
【问题讨论】:
标签: junit4
两种选择
编写一个 RunListener 并像这样使用它:
public void main(String... args) {
JUnitCore core= new JUnitCore();
core.addListener(new MyRunListener());
core.run(MyTestClass.class);
}
再写一个RunListener。但是这次扩展了一个 org.junit.runner.Runner 实现并覆盖了它的 run 方法,比如
@Override
public void run(RunNotifier notifier) {
notifier.addListener(new MyRunNotifier());
super.run(notifier);
}
第二种方法也可以用在带有 @RunWith(MyRunner.class) 注释的测试中。
【讨论】: