onTestSuccess() Exception incorrectly Triggers onTestFailure() and Fails Test

Open
#3,232 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java
Domain
testing-qa

Research direction

Start by reproducing the issue with the ITestListener callbacks shown in the report, then inspect TestInvoker where the test failure status is updated after onTestSuccess() throws. Add coverage for this sequence and verify that the test method remains passed, the report remains successful, and onTestFailure() is not invoked.

Written by the indexing model from the issue text.

Description

area: listeners effort: medium priority: medium status: confirmed status: needs discussion triage: ai-reviewed type: bug

TestNG Version
7.7.1
IITestListener

Expected behaviour

  • Test test passes
  • onTestSuccess
  • onTestFailure

Actual behaviour

  • Test status passes
  • onTestSuccess() throws exception
  • onTestFailure() is called
  • Test is reported as FAILED in the results.

Description
When the test method passes successfully, but an exception is thrown inside the onTestSuccess() listener method, TestNG incorrectly triggers onTestFailure() and marks the test as failed in the report.
The test case results should be based on the test method execution, not on listener behavior. Exceptions in onTestSuccess() should not affect the test status.
This behaviour seems like a bug or regression.

steps to repreduce

add an exception inside onTestSuccesss and check the ressults:
@Override
public void onTestSuccess(ITestResult result) {
// Throwing a runtime exception
throw new RuntimeException("exception in onTestSuccess");
}

@Override
public void onTestFailure(ITestResult result) {
    System.out.println("onTestFailure was  called");
}

note: while debugging the debugger navigated me to the TestInvoker class that update the test failuer to 2 which is FAILUER status then invoked onTestFailuer().

Dominant language
Java
Stars
2.1k
Forks
1k
Avg merge
2d 23h
Merged PRs (30d)
38

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testng-team/testng

All issues in testng-team/testng

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.