TestNG 7.4.0 Can not skip test through listener
See original GitHub issueIt looks like testng continue execute test even there is skip exception has been generated through listener
public class TestListener implements IInvokedMethodListener {
@Override
public void beforeInvocation(IInvokedMethod invokedMethod, ITestResult result) {
if (method.getName().contains("oneTest"))
throw new SkipException("skip test ...");
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
}
}
@Listeners({TestListener.class})
public class TestSample {
@Test()
public void oneTest() {
System.out.println("aaaaaaa");
Assert.assertEquals(1,2);
}
@Test()
public void twoTest() {
Assert.assertEquals(1,1);
}
}
when run TestSample ,
[Utils] [WARN] [Warning] Caught a [SkipException] exception from one of listeners com.sample.tests.TestListener. Will mark [com.sample.tests.TestSample.oneTest()] as SKIPPED.
aaaaaaa
.....
....
......
testNG still continue execute code .
BaseInvoker.java
catch the exception , but does not handle it properly …
InvokedMethodListenerInvoker invoker =
new InvokedMethodListenerInvoker(listenerMethod, testResult, testResult.getTestContext());
for (IInvokedMethodListener currentListener : m_invokedMethodListeners) {
try {
invoker.invokeListener(currentListener, invokedMethod);
} catch (SkipException e) {
String msg = String.format(
"Caught a [%s] exception from one of listeners %s. Will mark [%s()] as SKIPPED.",
SkipException.class.getSimpleName(), currentListener.getClass().getName(),
invokedMethod.getTestMethod().getQualifiedName());
Utils.warn(msg);
testResult.setStatus(ITestResult.SKIP);
testResult.setThrowable(e);
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (2 by maintainers)
Top Results From Across the Web
SkipException for multiple testclasses causes error in ... - GitHub
Since TestNG 7.0.0 there is an error when I try to skip the rest of test classes included in one testsuite. There are...
Read more >TestNG 7.4.0 - Released !
GITHUB-1632: throwing SkipException sets iTestResult status to Failure instead of Skip; GITHUB-2456: Add onDataProviderFailure listener; GITHUB- ...
Read more >Maven Surefire Plugin – Using TestNG
TestNG allows you to run your tests in parallel, including JUnit tests. To do this, you must set the parallel parameter, and may...
Read more >java - Error: org.testng.TestNGException: Cannot find class in ...
We are using maven project here and i am done with refreshing, cleaning, reinstalling testNG and then imported the maven projects but then...
Read more >TestNG (testng 7.5 API) - javadoc.io
By directly setting the test classes. You can also define which groups to include or exclude, assign parameters, etc... The command line parameters...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
System.out.println(“aaaaaaa”);
This line should not be executed when throw skip exception on listener
This issue is a duplicate of https://github.com/cbeust/testng/issues/2415
Closing this issue.