Timeout rule

Like the time out parameter example this snippet will show how to limit the execution time of a test with a junit @Rule. The Timeout Rule applies to all test methods within a class.

Timeout rule

@Rule public Timeout globalTimeout = new Timeout(100); // 10 seconds max per method tested

@Test
public void infinite_while_loop() {
    while (true) {
    }
}

@Test
public void infinite_for_loop() {
    for (;;) {
    }
}