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?开发者_Go百科
Screenshot
http://ge.tt/3ylDyiqWe 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(){
//...
}
}
精彩评论