Skip to content

Commit e4b2c06

Browse files
committed
Add CacheTest for dataprovider issue 3236
Introduces a new test class to verify dataprovider behavior with retries and caching disabled. The test ensures unique data per retry and validates invocation count.
1 parent d50b2ad commit e4b2c06

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package test.dataprovider.issue3236;
2+
3+
import static org.testng.Assert.assertEquals;
4+
5+
import java.util.UUID;
6+
import java.util.concurrent.atomic.AtomicInteger;
7+
import org.testng.IRetryAnalyzer;
8+
import org.testng.ITestResult;
9+
import org.testng.annotations.DataProvider;
10+
import org.testng.annotations.Test;
11+
12+
public class CacheTest {
13+
14+
public static final AtomicInteger invocationCount = new AtomicInteger(0);
15+
private String currentUuid;
16+
17+
@Test(dataProvider = "dp", retryAnalyzer = MyRetry.class)
18+
public void testMethod(String uuid) {
19+
assertEquals(currentUuid, uuid);
20+
if (invocationCount.get() != 2) {
21+
throw new RuntimeException("Failed for " + uuid);
22+
}
23+
}
24+
25+
@DataProvider(name = "dp", cacheDataForTestRetries = false)
26+
public Object[][] getData() {
27+
invocationCount.incrementAndGet();
28+
currentUuid = UUID.randomUUID().toString();
29+
return new Object[][]{{currentUuid}};
30+
}
31+
32+
public static class MyRetry implements IRetryAnalyzer {
33+
34+
private final AtomicInteger counter = new AtomicInteger(1);
35+
36+
@Override
37+
public boolean retry(ITestResult result) {
38+
return counter.getAndIncrement() != 2;
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)