question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TestNG 7.4.0 Can not skip test through listener

See original GitHub issue

It 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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bearxccommented, Apr 20, 2021

System.out.println(“aaaaaaa”);

This line should not be executed when throw skip exception on listener

0reactions
krmahadevancommented, Apr 25, 2021

This issue is a duplicate of https://github.com/cbeust/testng/issues/2415

Closing this issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found