JUnit5:DisableOnDebug 替代品?

JUnit5: DisableOnDebug replacement?

我正在从 JUnit4 迁移到 JUnit5。在 Junit4 中,我将 TimeoutDisableOnDebug 结合使用,如下所示:

    @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 中获得这种行为?

不幸的是,它不像创建规则那么简单(除非您考虑必须记住设置简单的 VM 参数)。您可以仅在调试时或始终通过此选项使用 VM 参数禁用超时

-Djunit.jupiter.execution.timeout.mode=disabled_on_debug

此处支持的选项有启用、禁用和disabled_on_debug

这在 JUnit 5 文档中有记载here