Skip to content

Commit 6f17547

Browse files
committed
Add a migration plan for TestMethodProviders.
1 parent 386ada4 commit 6f17547

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

etc/junit4-missing-features.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Random implementation. Optionally (parameter?) enable verifying that this Random
55
with other threads for reproducibility.
66

77
4. Shuffled test execution order and seed annotations
8-
- Test method execution order is randomized by default each run
98
- @Seed on a class fixes the main seed, making execution fully deterministic
109
- @Seeds / @Seed on a method pins a per-method seed for regression coverage
1110
while still running once with a fresh random seed
@@ -41,11 +40,6 @@ with other threads for reproducibility.
4140
- scaledRandomIntBetween() and multiplier() scale input sizes based on
4241
nightly vs. daily mode
4342

44-
14. Custom test-method providers
45-
- @TestMethodProviders({...}) substitutes the default (@Test-based) selector
46-
- Implement TestMethodProvider to pick methods by any criteria (e.g. name
47-
suffix convention)
48-
4943
2. RandomizedTest base class and RandomizedContext
5044
- Extend RandomizedTest for convenient access to a per-test Random instance
5145
- Access the context directly via RandomizedContext.current()

randomizedtesting-jupiter/src/test/java/com/carrotsearch/randomizedtesting/jupiter/F999_RemovedFeatures.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,24 @@ are run in discovery phase and execution contexts are not available then).
2626
## Custom event listeners (`@Listeners`).
2727

2828
* This feature is already part of JUnit5 (`TestExecutionListener`).
29+
30+
## Custom test-method providers (`@TestMethodProviders()`)
31+
32+
* JUnit5/ Jupiter offers many ways to discover tests dynamically. `@TestFactory`
33+
methods, templates, etc. While there is no one-to-one replacement, it should
34+
be possible to reimplement custom test providers with some minor refactorings.
35+
For example, if a `TestMethodProvider` was including all `test*` methods (JUnit3-style),
36+
you could write a `@TestFactory` in a common superclass and then just extend it. This
37+
test factory would something like this:
38+
```java
39+
@TestFactory
40+
Stream<DynamicTest> includeTestMethodsWithNoAnnotations() {
41+
return Arrays.stream(getClass().getDeclaredMethods())
42+
.filter(m -> m.getName().startsWith("test")
43+
&& m.getParameterCount() == 0
44+
&& !Modifier.isStatic(m.getModifiers()))
45+
.map(m -> DynamicTest.dynamicTest(m.getName(), () -> {
46+
m.invoke(this);
47+
}));
48+
}
49+
```

0 commit comments

Comments
 (0)