You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Test method is retried according to IRetryAnalyzer configuration when parameters are modified before rerun
Actual behavior
Test method is retried endlessly when parameters are modified before rerun
Is the issue reproducible on runner?
Shell
Maven
Gradle
Ant
Eclipse
IntelliJ
NetBeans
Summary:
In my current project, test data needs to be slightly modified during retries because the data is saved to a database during test execution and on reruns, errors occur due to the data already existing in the database.
To handle this, parameters are modified within the ITestListener.onTestSkipped method during reruns to generate new values for each retry. The object remains the same type, but some fields (e.g., description or UUID-number) are updated.
Issue:
After upgrading TestNG from 7.7.1 to 7.10.2, test methods with updated parameters are invoked endlessly.
While debugging, I traced the issue to the method org.testng.internal.BaseTestMethod.getRetryAnalyzerConsideringMethodParameters(ITestResult tr). In this method, a unique keyAsString is generated for each rerun, which results in the creation of a new IRetryAnalyzer every time.
Corresponding PR: #2935
Additional Info:
I attempted to use DataProvider with cacheDataForTestRetries = false, but it fails to supply new parameters to the test methods.
As a result, I'm currently blocked from upgrading TestNG due to this issue.
Related issue: #3157
Related pr: #3076
@Riabchykova - The problem lies in your test code and not with TestNG
You are using the lombok annotation @Data. This is a short cut for generating the following
@Getter
@Setter
@RequiredArgsConstructor
@ToString
@EqualsAndHashCode
Now the thing that is goofing up your code is the @EqualsAndHashCode which by default considers the data members in your SomeDataEntity to generate the hashCode.
Everytime you alter your name parameter via the randomize() function, you are effectively altering the uniqueness of the SomeDataEntity object and thus causing TestNG to work with different test data.
You can fix this by doing one of the following after you get rid of the @Data annotation.
Use @Getter because that is the only thing that you are using to retrieve the value in your test class (or)
Abandon lombok annotation and use the classic way of working with getters/setters which can be generated by IntelliJ IDE.
Am closing this issue. Please feel free to comment back (possibly with a simple standalone project instead of the sample code) if the issue persists.
In a nutshell your @Data is what is goofing up things and it's very easy to miss its havoc :)
@krmahadevan
Thank you for your thorough investigation and detailed explanation! I’ve made the changes you suggested, and the solution works perfectly. I appreciate your help in identifying the root cause. Thanks again for your support!
TestNG Version
7.10.2
Expected behavior
Test method is retried according to IRetryAnalyzer configuration when parameters are modified before rerun
Actual behavior
Test method is retried endlessly when parameters are modified before rerun
Is the issue reproducible on runner?
Summary:
In my current project, test data needs to be slightly modified during retries because the data is saved to a database during test execution and on reruns, errors occur due to the data already existing in the database.
To handle this, parameters are modified within the ITestListener.onTestSkipped method during reruns to generate new values for each retry. The object remains the same type, but some fields (e.g., description or UUID-number) are updated.
Issue:
After upgrading TestNG from 7.7.1 to 7.10.2, test methods with updated parameters are invoked endlessly.
While debugging, I traced the issue to the method org.testng.internal.BaseTestMethod.getRetryAnalyzerConsideringMethodParameters(ITestResult tr). In this method, a unique keyAsString is generated for each rerun, which results in the creation of a new IRetryAnalyzer every time.
Corresponding PR: #2935
Additional Info:
I attempted to use DataProvider with cacheDataForTestRetries = false, but it fails to supply new parameters to the test methods.
As a result, I'm currently blocked from upgrading TestNG due to this issue.
Related issue: #3157
Related pr: #3076
Test case sample
Test class
RetryListener class
Retrier class
Randomizer interface
retry_testng.xml
The output during the test run is as follows:
The text was updated successfully, but these errors were encountered: