I found the following example in JUnit documentation:
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) {}
}
}
I understand that whenever JUnit tries to interrupt the first test, it will interrupt the thread where it is running on, and it will throw an InterruptedException, leading to the test being finished.
But what about the second test (infiniteLoop)? It is not throwing anything. How is it stopped after the timeout?