I want to run a unit test with a time-out that is defined at runtime. I want to define a time-out for a specific test only, not the whole class.
I saw these are the ways to set the time out:
@Rule
public Timeout globalTimeout = new Timeout(10000); // 10 seconds max per method tested
or
@Test(timeout=100) public void infinity() {
while(true);
}
but when I run this code, no exception is thrown. I want to identify when the test failed due to timeout.
public Timeout testTimeout;
private void setTestTimeOut() {
if (!Strings.isNullOrEmpty(testTimeOut)) {
testTimeout = new Timeout(Integer.parseInt(testTimeOut));
}
}
How can I catch the exception? Wrap the main method with try-catch(InterruptException)
?