public class TimeOutExample {
//Here the expectation is that to execute testMethod 10 times it should not take more than 900 ms.
//But every iteration is going to sleep for 100 ms. So running it for 10 times is going to take 1 second.
@Test (invocationTimeOut = 900, invocationCount = 10)
public void testMethod() throws InterruptedException {
Thread.sleep(100); //Sleep for 0.1 seconds
}
}
When this method is executed you will see the below exception
org.testng.internal.thread.ThreadTimeoutException: Method org.testng.internal.TestNGMethod.testMethod() didn't finish within the time-out 900
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Pratik,
Yes, what you see as a behavior by TestNG is perhaps a bit counter intuitive and maybe even consuming. But TestNG here is working as designed.
Let me explain my understanding of the current behavior that TestNG is exhibiting.
@Test(invocationCount=5)
public void testMethod() throws InterruptedException {
Thread.sleep(100);
System.out.println("Print....");
}
In the above sample, we are telling TestNG that we want it to invoke testMethod “5” times. That explains the below result
Print....
Print....
Print....
Print....
Print....
===============================================
Default Suite
Total tests run: 5, Passes: 5, Failures: 0, Skips: 0
===============================================
But when you have a sample that looks like below:
@Test(invocationCount = 5, invocationTimeOut = 1000)
public void testMethod() throws InterruptedException {
Thread.sleep(100);
System.out.println("Print....");
}
Here we are telling TestNG that we want it to run “testMethod” to run 5 times but the overall timeout across all the invocations would be 1000 milli seconds. That is why the 5 iterations gets wrapped into just 1 invocation and reported as below:
Print....
Print....
Print....
Print....
Print....
===============================================
Default Suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
Quoting the javadocs as well,
The maximum number of milliseconds that the total number of invocations on this test method should take. This annotation will be ignored if the attribute invocationCount is not specified on this method. If it hasn't returned after this time, it will be marked as a FAIL.
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.com/
--