Skip to content

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

@ahmadserese

Description

@ahmadserese

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions