JUnit 4 Tutorial 4 – Time Test
Published: May 20, 2009 , Updated: April 1, 2010 , Author: mkyong
The “Time Test” means if an unit test takes longer than the specified number of milliseconds to run, the test will terminated and mark as failed.
import org.junit.*;
/**
* JUnit TimeOut Test
* @author mkyong
*
*/
public class JunitTest4 {
@Test(timeout = 1000)
public void infinity() {
while (true);
}
}In above example, the infinity() method will not return, so the JUnit engine will mark it as failed and throw an exception
java.lang.Exception: test timed out after 1000 milliseconds
Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
[...] Tutorial 4 – Time Test Make sure the testing method will return after certain time. [...]