forked from testng-team/testng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow data providers to be non cacheable
Closes testng-team#3041 We can now configure TestNG to enable/disable caching of test data produced by a data provider when TestNG is retrying a failed test method using the attribute “cacheDataForTestRetries” on the “@dataProvider” annotation. Below is a sample, which forces TestNG to re-invoke the data provider when a test method fails and it needs to be retried. ``` @dataProvider(name = "dp", cacheDataForTestRetries = false) public Object[][] getData() { return new Object[][] {{1}, {2}}; } ```
- Loading branch information
1 parent
2cc332d
commit 57424cf
Showing
11 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
testng-core/src/test/java/test/dataprovider/issue3041/SampleTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package test.dataprovider.issue3041; | ||
|
||
import java.util.Random; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.testng.IRetryAnalyzer; | ||
import org.testng.ITestResult; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class SampleTestCase { | ||
|
||
public static final AtomicInteger invocationCount = new AtomicInteger(0); | ||
private static final Random random = new Random(); | ||
|
||
@Test(dataProvider = "dp", retryAnalyzer = MyRetry.class) | ||
public void testMethod(int i) { | ||
if (invocationCount.get() != 2) { | ||
throw new RuntimeException("Failed for " + i); | ||
} | ||
} | ||
|
||
@DataProvider(name = "dp", cacheDataForTestRetries = false) | ||
public Object[][] getData() { | ||
invocationCount.incrementAndGet(); | ||
return new Object[][] {{next()}, {next()}}; | ||
} | ||
|
||
private static int next() { | ||
return random.nextInt(); | ||
} | ||
|
||
public static class MyRetry implements IRetryAnalyzer { | ||
|
||
private final AtomicInteger counter = new AtomicInteger(1); | ||
|
||
@Override | ||
public boolean retry(ITestResult result) { | ||
return counter.getAndIncrement() != 2; | ||
} | ||
} | ||
} |