Google News
logo
JUnit - Interview Questions
Can you test a Java method for timeout using JUnit?
Yes, JUnit provides a timeout parameter to @Test annotation which can be used to instruct JUnit to pass or fail a test method based upon execution time. For example, a JUnit test method annotated with @Test(timeout= 50) will be failed it doesn't complete in 50 milliseconds (timeout is specified in millisecond). This is the standard way to verify the SLA of a Java method.
Advertisement