I am having API test suite where few tests taking a great amount time causing test suite to run more than 5-6+ hrs. Is there any way to skip certain tests which exceeds run time for that particular test in TestNG.
Asked
Active
Viewed 131 times
0
-
I think [this answer](https://stackoverflow.com/questions/3945769/how-to-disable-testng-test-based-on-a-condition) might help you. You'll have to identify and "mark" the long-running tests beforehand as TestNG cannot know how much time they take before they were running. – ahuemmer Sep 15 '22 at 07:59
1 Answers
0
First you implement IInvokeMethodListener
where you do:
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult){
if(testResult.getThrowable() instanceof ThreadTimeoutException){
testResult.setStatus(ITestResult.SKIP);
}
}
Say you implemented it in MyImpl
class. Then you could have:
@Listeners({MyImpl.class})
public class MyTest {
@Test(timeOut = 1)
public void test(){
// Do long task that takes more than 1 ms
// The test will be skipped
}
}

Alexey R.
- 8,057
- 2
- 11
- 27