Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestResult.isSuccess() is TRUE when test fails due to expectedExceptions #2788

Closed
2 tasks done
ben-manes opened this issue Jul 31, 2022 · 0 comments · Fixed by #2815
Closed
2 tasks done

TestResult.isSuccess() is TRUE when test fails due to expectedExceptions #2788

ben-manes opened this issue Jul 31, 2022 · 0 comments · Fixed by #2815

Comments

@ben-manes
Copy link
Contributor

ben-manes commented Jul 31, 2022

TestNG Version

7.6.1

Expected behavior

IInvokedMethodListener.afterInvocation(method, result) should receive a result with the status FAILURE.

Actual behavior

The status is SUCCESS and getThrowable() is set to a TestException from ExpectedExceptionsHolder.noException.

Is the issue reproducible on runner?

Yes, minimally

  • Gradle
  • Eclipse

Test case sample

@Test(expectedExceptions = NullPointerException.class)
public void test() {}

Impact

To handle running 10M+ unit tests, my IInvokedMethodListener tries to reclaim memory for successful tests. This avoids out-of-memory errors and long GC pauses, e.g. by replacing test parameters with their stringified version. This also unset the throwable, which causes Gradle's runner to fail with an obscure NPE (gradle/gradle#21336) as it was not defensive to failures without a cause (whereas the Eclipse plugin is tolerant). My fix is to stop nulling out the throwable as it is lightweight enough to retain. However, others might similarly be surprised by the premature success and report it incorrectly in their logic.

Possible Fix

I suspect that adding testResult.setStatus(ITestResult.FAILURE) to the below code would be the correct change. That requires a little rework to retain the originalStatus.

https://github.com/cbeust/testng/blob/b5b3e1d0f8db429b1bb5d1d675ddf5940d19f92c/testng-core/src/main/java/org/testng/internal/invokers/TestInvoker.java#L865-L872

krmahadevan added a commit to krmahadevan/testng that referenced this issue Oct 31, 2022
krmahadevan added a commit to krmahadevan/testng that referenced this issue Oct 31, 2022
krmahadevan added a commit to krmahadevan/testng that referenced this issue Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant