1

我需要禁用长时间运行的junit测试的超时,但我正在尝试的任何东西都无法正常工作。

首先,我尝试使用以下方法将超时时间延长至极长的时间。

@Test(timeout = Long.MAX_VALUE)

从理论上讲,这应该将超时延长到相当于大约 2.92 亿年的毫秒数,但测试在大约 300 分钟后仍然超时。

接下来,我尝试了以下方法:

@Rule
public TestRule timeout = new DisableOnDebug(new Timeout(20, TimeUnit.SECONDS));

如果我在没有调试模式的情况下运行测试,它们会在大约 20 秒内超时。这是预期的。但是,即使在调试模式下,我仍然会在大约 300-400 分钟后看到超时(从不一样)。我不知道这个超时在哪里触发或什么超时触发:

这是超时的摘录:

[junit] Testcase: myTest took 0.002 sec
[junit]     Caused an ERROR
[junit] Timeout occurred. Please note the time in the report does not reflect the time until the timeout.
[junit] junit.framework.AssertionFailedError: Timeout occurred. Please note the time in the report does not reflect the time until the timeout.
[junit]     at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[junit]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

这可能是什么原因?我怎样才能完全禁用超时?

更新:我应该注意,如果没有通过注释或规则指定超时,我仍然会看到超时。

4

0 回答 0