【发布时间】:2016-06-20 09:24:55
【问题描述】:
我需要在 JUnit 4 测试框架中测量每个方法的方法执行时间。 考虑这个测试:
package org.test.libtest
import org.some.lib.Class
..
public class testMyApp{
@Test
public void testSomething(){
//Asume following method returns a Long value after doing a complex calc
int a=100, b=100;
Long ac=org.some.lib.Class.doSomething(int a, int b);
Assert.assertEquals(100,ac);
}
..
..
}
要求是测量方法org.some.lib.Class.doSomething(..)执行的时间。
我们可以通过使用 Spring AOP 和 Junit 自己的 @Rule、Stopwatch 类的测试方法 testMyApp 来获取执行时间。 但是我们如何测量一个测试方法调用底层方法执行的时间呢?
【问题讨论】:
-
PerformanceMonitorInterceptor之类的东西会为您做到这一点。
标签: java spring unit-testing junit aop