Closed outofrange closed 4 years ago
This issue still exists with TestNG 6.8.7.
I would try to take a deeper look into it, if somebody could confirm this as a bug (and not expected behaviour).
TestNG injects an ITestResult
object for the @Test
method that got executed, into @AfterMethod
annotated method.
But for the following methods, its the same ITestResult
object for a configuration method that gets executed.
org.testng.IConfigurationListener#beforeConfiguration
org.testng.IInvokedMethodListener#beforeInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)
org.testng.IInvokedMethodListener#afterInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)
org.testng.IConfigurationListener#onConfigurationFailure
Closing this issue (TestNG is working as designed in terms of not injecting the ITestResult
object of a failed configuration in an @AfterMethod
method)
I am using a TestListener to catch errors and store the exception message into the IAttributes of ITestResult (see https://github.com/outofrange/testresultbug/blob/master/testresultbug/src/main/java/org/outofrange/bugproject/MyListener.java)
Debugging in Eclipse also shows different ids for ITestResult in the listener and my teardown method.
I would expect the same behaviour of TestNG in both cases, giving me the same instance of ITestResult.
Example test for case 1.: https://github.com/outofrange/testresultbug/blob/master/testresultbug/src/main/java/org/outofrange/bugproject/MyTestFailure.java Output:
Detected a failure, setting failreason Test failed because of: AssertionError: failure in test method expected [true] but found [false]
Example test for case 2.: https://github.com/outofrange/testresultbug/blob/master/testresultbug/src/main/java/org/outofrange/bugproject/MyConfigurationFailure.java Output:
Detected a failure, setting failreason Test failed because of: null
I've created a complete example maven project (using TestNG 6.8.5) here: https://github.com/outofrange/testresultbug