我正在从JUnit4迁移到JUnit5。在Junit4中,我将Timeout与DisableOnDebug结合使用,如下所示:
@Rule
public TestRule rule = new DisableOnDebug(new Timeout(1, TimeUnit.SECONDS));
@Test
public void verify_computation_terminates() {
// Verify that the algorithm can solve a given problem in a reasonable
// amount of time; relevant for NP problems.
int result = do_complex_computation();
assertEquals(42, result);
}当我调试到do_complex_computation()时,超时将被禁用,否则调试会话将停止。
然而,规则在JUnit5中被删除。
我如何在JUnit5中得到这种行为呢?
发布于 2021-02-16 23:32:08
不幸的是,它并不像创建规则那么简单(除非您考虑必须记住将VM参数设置得很简单)。您可以仅在调试时使用VM参数禁用超时,也可以始终通过此选项禁用超时。
-Djunit.jupiter.execution.timeout.mode=disabled_on_debug这里支持的选项被启用、禁用和disabled_on_debug
这在JUnit 5文档这里中有记录。
https://stackoverflow.com/questions/62189659
复制相似问题