I am using TestNG @DataProvider for passing objects as test parameters and Retry class (that extends RetryAnalyzerCount) to retry failed tests.
All is working fine except: if some of object properties were changed during test before it fails, dataProvider method is running on retry but don't pass new object to test, so in test we have old set data from 1st run.
Example:
@DataProvider(name = "userData")
public static Object[] getUserData() {
System.out.println("DataProvider is started...");
TestUser testUser = new TestUser("John");
System.out.println("Username from dataprovider: " + testUser.getName());
return new Object[]{testUser};
}
@Test(retryAnalyzer = Retry.class, dataProvider = "userData")
public void testRetry(TestUser user) {
System.out.println("Test is started...");
System.out.println("Username from test: " + user.getName());
user.setName("New Name");
Assert.fail();
}
Output:
DataProvider is started...
Username from dataprovider: John
Test is started...
Username from test: John
Retry test...
DataProvider is started...
Username from dataprovider: John
Test is started...
Username from test: New Name
TestNG version: 7.6.0, 7.7.1
Facing such issue and don't know how to get around it.
There is no issue here.
Here's a sample that re-iterates all these aspects. For the sake of completeness I have added the same details to your post on the TestNG google users group as well.
Test class sample (I am using
7.7.1which is the latest released version for running this test)Here's the complete execution output, along with some inline comments that I have added for elaboration:
Points to note:
Pojo@2bfc268bthat was created the first time the data provider was called, is what is being passed to the test method when a retry is happening and so the name that was changed by me in the test method is what is coming back when the test is getting retried (which is whyJohnbecameDragon-Warrior)Pojo@2b91004a,Pojo@169e6180to be created, but if you look at the execution output, you would notice that its not being used by the test method. This is a bug which is now being tracked by the above mentioned github issue.