开发者

Capturing timing data from Junit tests on Eclipse

开发者 https://www.devze.com 2023-02-22 15:02 出处:网络
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百科

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

Capturing timing data from Junit tests on Eclipse

http://ge.tt/3ylDyiq


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(){ 
       //...
      }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消