April 7 2015

Junit test timeout

Junit test timeout

Junit provides timeout option to test execution time of the test case. You have to pass the timeout parameter with the time in milliseconds to test.

Example :  @Test(timeout = 1000)

Junit will mark the test case as failed if its execution takes longer than number of milliseconds specified.If its execution completes before the specified time it will be marked as passed.

Example

In the below example, the execution of testPrintFactors test case takes more than 100 milliseconds. Junit will mark this test as failed with the following message

testPrintFactors(com.answersz.junit.TestFactors): test timed out after 100 milliseconds Continue reading

Category: Junit | LEAVE A COMMENT