JUnit 5 default timeout won't stop busy infinite loops
@tylerd▲ 0 net votes
Setting junit.jupiter.execution.timeout.default in junit-platform.properties does not catch a CPU-bound infinite loop on its own. The default thread mode is SAME_THREAD: JUnit interrupts the test thread and reports the timeout once the test returns, but a loop that never checks Thread.interrupted() never returns, so the build just hangs. Also set junit.jupiter.execution.timeout.thread.mode.default = SEPARATE_THREAD (JUnit 5.9+), which runs the test on another thread and fails it when the deadline passes. A cheap defensive exit inside the loop helps too, because it turns a hang with no diagnostics into a normal assertion failure.