-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce option on @dataProvider if its result should be cached (#105)
- Loading branch information
Showing
24 changed files
with
482 additions
and
133 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...Test/java/com/tngtech/test/junit/dataprovider/CacheDataProviderResultsAcceptanceTest.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,65 @@ | ||
package com.tngtech.test.junit.dataprovider; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
|
||
import com.tngtech.junit.dataprovider.DataProvider; | ||
import com.tngtech.junit.dataprovider.UseDataProvider; | ||
|
||
class CacheDataProviderResultsAcceptanceTest { | ||
|
||
// works if test discovery order is equal to execution order | ||
public static final AtomicInteger noOfTestsCallsUsingNotCachedDataProvider = new AtomicInteger(0); | ||
|
||
private static final AtomicInteger noOfCachedDataProviderCalls = new AtomicInteger(0); | ||
private static final AtomicInteger noOfNotCachedDataProviderCalls = new AtomicInteger(0); | ||
|
||
@DataProvider | ||
static Object[][] dataProviderCachedDataProviderResults() { | ||
// @formatter:off | ||
return new Object[][] { | ||
{ noOfCachedDataProviderCalls.incrementAndGet() }, | ||
}; | ||
// @formatter:on | ||
} | ||
|
||
@ParameterizedTest | ||
@UseDataProvider("dataProviderCachedDataProviderResults") | ||
void testCachedDataProviderResultsOne(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(1); | ||
} | ||
|
||
@ParameterizedTest | ||
@UseDataProvider("dataProviderCachedDataProviderResults") | ||
void testCachedDataProviderResultsTwo(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(1); | ||
} | ||
|
||
@DataProvider(cache = false) | ||
public static Object[][] dataProviderDoNotCacheDataProviderResults() { | ||
// @formatter:off | ||
return new Object[][] { | ||
{ noOfNotCachedDataProviderCalls.incrementAndGet() }, | ||
}; | ||
// @formatter:on | ||
} | ||
|
||
@ParameterizedTest | ||
@UseDataProvider("dataProviderDoNotCacheDataProviderResults") | ||
public void testDoNotCacheDataProviderResultsOne(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(noOfTestsCallsUsingNotCachedDataProvider.incrementAndGet()); | ||
} | ||
|
||
@ParameterizedTest | ||
@UseDataProvider("dataProviderDoNotCacheDataProviderResults") | ||
public void testDoNotCacheCachedDataProviderResultsTwo(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(noOfTestsCallsUsingNotCachedDataProvider.incrementAndGet()); | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
...est/java/com/tngtech/test/junit/dataprovider/CachedDataProviderResultsAcceptanceTest.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
.../com/tngtech/test/junit/dataprovider/CachedDataProviderResultsGloballyAcceptanceTest.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,40 @@ | ||
package com.tngtech.test.junit.dataprovider; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
|
||
import com.tngtech.junit.dataprovider.UseDataProvider; | ||
|
||
class CachedDataProviderResultsGloballyAcceptanceTest { | ||
|
||
@ParameterizedTest | ||
@UseDataProvider(value = "dataProviderCachedDataProviderResults", location = CacheDataProviderResultsAcceptanceTest.class) | ||
void testCachedDataProviderResultsOne(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(1); | ||
} | ||
|
||
@ParameterizedTest | ||
@UseDataProvider(value = "dataProviderCachedDataProviderResults", location = CacheDataProviderResultsAcceptanceTest.class) | ||
void testCachedDataProviderResultsTwo(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(1); | ||
} | ||
|
||
@ParameterizedTest | ||
@UseDataProvider(value = "dataProviderDoNotCacheDataProviderResults", location = CacheDataProviderResultsAcceptanceTest.class) | ||
public void testDoNotCacheDataProviderResultsOne(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo( | ||
CacheDataProviderResultsAcceptanceTest.noOfTestsCallsUsingNotCachedDataProvider.incrementAndGet()); | ||
} | ||
|
||
@ParameterizedTest | ||
@UseDataProvider(value = "dataProviderDoNotCacheDataProviderResults", location = CacheDataProviderResultsAcceptanceTest.class) | ||
public void testDoNotCacheCachedDataProviderResultsTwo(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo( | ||
CacheDataProviderResultsAcceptanceTest.noOfTestsCallsUsingNotCachedDataProvider.incrementAndGet()); | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
...Test/java/com/tngtech/test/junit/dataprovider/CacheDataProviderResultsAcceptanceTest.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,68 @@ | ||
package com.tngtech.test.junit.dataprovider; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import com.tngtech.junit.dataprovider.DataProvider; | ||
import com.tngtech.junit.dataprovider.UseDataProvider; | ||
import com.tngtech.junit.dataprovider.UseDataProviderExtension; | ||
|
||
@ExtendWith(UseDataProviderExtension.class) | ||
class CacheDataProviderResultsAcceptanceTest { | ||
|
||
// works if test discovery order is equal to execution order | ||
public static final AtomicInteger noOfTestsCallsUsingNotCachedDataProvider = new AtomicInteger(0); | ||
|
||
private static final AtomicInteger noOfCachedDataProviderCalls = new AtomicInteger(0); | ||
private static final AtomicInteger noOfNotCachedDataProviderCalls = new AtomicInteger(0); | ||
|
||
@DataProvider | ||
static Object[][] dataProviderCachedDataProviderResults() { | ||
// @formatter:off | ||
return new Object[][] { | ||
{ noOfCachedDataProviderCalls.incrementAndGet() }, | ||
}; | ||
// @formatter:on | ||
} | ||
|
||
@TestTemplate | ||
@UseDataProvider("dataProviderCachedDataProviderResults") | ||
void testCachedDataProviderResultsOne(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(1); | ||
} | ||
|
||
@TestTemplate | ||
@UseDataProvider("dataProviderCachedDataProviderResults") | ||
void testCachedDataProviderResultsTwo(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(1); | ||
} | ||
|
||
@DataProvider(cache = false) | ||
public static Object[][] dataProviderDoNotCacheDataProviderResults() { | ||
// @formatter:off | ||
return new Object[][] { | ||
{ noOfNotCachedDataProviderCalls.incrementAndGet() }, | ||
}; | ||
// @formatter:on | ||
} | ||
|
||
@TestTemplate | ||
@UseDataProvider("dataProviderDoNotCacheDataProviderResults") | ||
public void testDoNotCacheDataProviderResultsOne(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(noOfTestsCallsUsingNotCachedDataProvider.incrementAndGet()); | ||
} | ||
|
||
@TestTemplate | ||
@UseDataProvider("dataProviderDoNotCacheDataProviderResults") | ||
public void testDoNotCacheCachedDataProviderResultsTwo(int noOfDataProvderCalls) { | ||
// Expected: | ||
assertThat(noOfDataProvderCalls).isEqualTo(noOfTestsCallsUsingNotCachedDataProvider.incrementAndGet()); | ||
} | ||
} |
Oops, something went wrong.