从Eclipse的Junit测试中捕获时序数据 [英] Capturing timing data from Junit tests on Eclipse
本文介绍了从Eclipse的Junit测试中捕获时序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Eclipse Galileo(3.5)上运行,我注意到我的测试显示了每次测试运行的时间。有没有办法捕获和这些信息?是否有API或存储在结果文件中?
Running on Eclipse Galileo (3.5), I noticed my tests show the timing of each test run. Is there a way to capture and this information? Is there an API or is it stored in a result file?
截图
推荐答案
我们可以使用Rule获取每个测试方法的持续时间:
We could use Rule to get time durations for each test method:
class TimeConsumeRule implements MethodRule {
@Override
public Statement apply(final Statement base, final FrameworkMethod method, Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
long start = System.currentTimeMillis();
try {
base.evaluate();
} finally {
System.out.println(method.getName()+ " used "+ (System.currentTimeMillis() - start)+" ms;");
}
}
};
}
}
public class TimeConsume {
//Just declare customized Rule in your test case.
@Rule
public MethodRule rule = new TimeConsumeRule();
@Test
public void test1(){
//...
}
@Test
public void test2(){
//...
}
}
这篇关于从Eclipse的Junit测试中捕获时序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文