我需要记录每个测试用例的执行时间。我不想使用自定义实现。我想知道 junit5 Btw 中是否有可用的注释
,我知道Stopwatch
或 Junit4 @Timeout
。
问问题
2863 次
4 回答
6
在查看了 junit5 文档后,我发现了这个示例 TimeExtension
这个片段来自他们的文档:
@ExtendWith(TimingExtension.class)
class TimingExtensionTests {
@Test
void sleep20ms() throws Exception {
Thread.sleep(20);
}
@Test
void sleep50ms() throws Exception {
Thread.sleep(50);
}
}
于 2017-07-21T05:17:26.913 回答
2
我写了一个BenchmarkExtension
你可以申请的@Benchmark
。您可以按如下方式使用它:
@Benchmark
class BenchmarkTest {
@Test
void notBenchmarked() {
assertTrue(true);
}
@Test
@Benchmark
void benchmarked() throws InterruptedException {
Thread.sleep(100);
assertTrue(true);
}
}
当应用于该类时,您将收到一条消息,其中包含该类中所有测试方法的总运行时间。当应用于单个测试方法时,您将仅收到该测试的消息。
我希望它最终会进入JUnit Pioneer。
于 2017-07-21T05:39:50.343 回答