例如,我有一个方法可以使用以下一些操作“加、减、乘、除”来计算两个数字并返回结果。
public int sum(int a, int b) {
return a + b;
}
如果计算时间不超过 0.5 秒,我是否可以测试该方法的执行时间?
最佳答案
使用 @Test(timeout=1000)
注释您的测试方法。
Timeout parameter on @Test Annotation (applies to test method)
You can optionally specify timeout in milliseconds to cause a test method to fail if it takes longer than that number of milliseconds. If the time limit is exceeded, the the failure is triggered by an Exception being thrown:
查看junit doku .
关于java - JUnit:测试计算速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24249136/