The Timeout Rule applies the same timeout to all test methods in a class:
public static class HasGlobalLongTimeout { @Rule public Timeout globalTimeout= new Timeout(20); @Test public void run1() throws InterruptedException { Thread.sleep(100); } @Test public void infiniteLoop() { while (true) {} } }
Each test is run in a new thread. If the specified timeout elapses before the test completes, its execution is interrupted via {@link Thread#interrupt()}. This happens in interruptable I/O and locks, and methods in {@link Object}and {@link Thread} throwing {@link InterruptedException}.
A specified timeout of 0 will be interpreted as not set, however tests will still launch from separate threads. This can be useful for disabling timeouts in environments where they are dynamically set based on some property.
@since 4.7