Skip to content

Commit a5343b3

Browse files
authored
Merge pull request #45253 from gsmet/assorted-withtestresource-fixes
Assorted @WithTestResource fixes
2 parents f253d80 + 48d51cd commit a5343b3

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

docs/src/main/asciidoc/getting-started-testing.adoc

+7-7
Original file line numberDiff line numberDiff line change
@@ -1224,20 +1224,20 @@ public @interface WithRepeatableTestResource {
12241224
}
12251225
----
12261226

1227-
=== Usage of `@WithTestResources`
1227+
=== Usage of `@WithTestResource`
12281228

1229-
While test resources provided by `@QuarkusTestResource` are available either globally or restricted to the annotated test class (`restrictToAnnotatedClass`), the annotation `@WithTestResources` allows to additionally group tests by test resources for execution.
1230-
`@WithTestResources` has a `scope` property that takes a `TestResourceScope` enum value:
1229+
While test resources provided by `@QuarkusTestResource` are available either globally or restricted to the annotated test class (`restrictToAnnotatedClass`), the annotation `@WithTestResource` allows to additionally group tests by test resources for execution.
1230+
`@WithTestResource` has a `scope` property that takes a `TestResourceScope` enum value:
12311231

12321232
- `TestResourceScope.MATCHING_RESOURCES` (default): Quarkus will group tests with the same test resources and run them together. After a group has been executed, all test resources will be stopped, and the next group will be executed.
12331233
- `TestResourceScope.RESTRICTED_TO_CLASS`: The test resource is available only for the annotated test class and will be stopped after the test class has been executed.
1234-
- `TestResourceScope.GLOBAL`: Test resources apply to all tests in the testsuite
1234+
- `TestResourceScope.GLOBAL`: Test resources apply to all tests in the test suite
12351235

12361236
Quarkus needs to restart if one of the following is true:
12371237

1238-
- At least one the existing test resources is restricted to the test class
1239-
- At least one the next test resources is restricted to the test class
1240-
- Different {@code MATCHING_RESOURCE} scoped test resources are being used
1238+
- At least one of the test resources of the current test is restricted to the test class
1239+
- At least one of the test resources of the next test is restricted to the test class
1240+
- Different `MATCHING_RESOURCES` scoped test resources are being used
12411241

12421242
== Hang Detection
12431243

test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ public TestResourceManager(Class<?> testClass,
106106

107107
this.testResourceComparisonInfo = new HashSet<>();
108108
for (TestResourceClassEntry uniqueEntry : uniqueEntries) {
109-
testResourceComparisonInfo.add(new TestResourceComparisonInfo(
110-
uniqueEntry.testResourceLifecycleManagerClass().getName(), uniqueEntry.getScope(), uniqueEntry.args));
109+
testResourceComparisonInfo.add(prepareTestResourceComparisonInfo(uniqueEntry));
111110
}
112111

113112
Set<TestResourceClassEntry> remainingUniqueEntries = initParallelTestResources(uniqueEntries);
@@ -331,7 +330,7 @@ private Set<TestResourceClassEntry> uniqueTestResourceClassEntries(Path testClas
331330
}
332331

333332
/**
334-
* Allows Quarkus to extra basic information about which test resources a test class will require
333+
* Allows Quarkus to extract basic information about which test resources a test class will require
335334
*/
336335
public static Set<TestResourceManager.TestResourceComparisonInfo> testResourceComparisonInfo(Class<?> testClass,
337336
Path testClassLocation, List<TestResourceClassEntry> entriesFromProfile) {
@@ -343,16 +342,24 @@ public static Set<TestResourceManager.TestResourceComparisonInfo> testResourceCo
343342
allEntries.addAll(entriesFromProfile);
344343
Set<TestResourceManager.TestResourceComparisonInfo> result = new HashSet<>(allEntries.size());
345344
for (TestResourceClassEntry entry : allEntries) {
346-
Map<String, String> args = new HashMap<>(entry.args);
347-
if (entry.configAnnotation != null) {
348-
args.put("configAnnotation", entry.configAnnotation.annotationType().getName());
349-
}
350-
result.add(new TestResourceComparisonInfo(entry.testResourceLifecycleManagerClass().getName(), entry.getScope(),
351-
args));
345+
result.add(prepareTestResourceComparisonInfo(entry));
352346
}
353347
return result;
354348
}
355349

350+
private static TestResourceComparisonInfo prepareTestResourceComparisonInfo(TestResourceClassEntry entry) {
351+
Map<String, String> args;
352+
if (entry.configAnnotation != null) {
353+
args = new HashMap<>(entry.args);
354+
args.put("configAnnotation", entry.configAnnotation.annotationType().getName());
355+
} else {
356+
args = entry.args;
357+
}
358+
359+
return new TestResourceComparisonInfo(entry.testResourceLifecycleManagerClass().getName(), entry.getScope(),
360+
args);
361+
}
362+
356363
private static Set<TestResourceClassEntry> getUniqueTestResourceClassEntries(Class<?> testClass,
357364
Path testClassLocation,
358365
Consumer<Set<TestResourceClassEntry>> afterMetaAnnotationAction) {

test-framework/junit5/src/main/java/io/quarkus/test/junit/util/QuarkusTestProfileAwareClassOrderer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ public void orderClasses(ClassOrdererContext context) {
122122
})
123123
.orElseGet(ClassName::new).orderClasses(context);
124124

125-
var classDecriptors = context.getClassDescriptors();
126-
var firstPassIndexMap = IntStream.range(0, classDecriptors.size()).boxed()
127-
.collect(Collectors.toMap(classDecriptors::get, i -> String.format("%06d", i)));
125+
var classDescriptors = context.getClassDescriptors();
126+
var firstPassIndexMap = IntStream.range(0, classDescriptors.size()).boxed()
127+
.collect(Collectors.toMap(classDescriptors::get, i -> String.format("%06d", i)));
128128

129129
// second pass: apply the actual Quarkus aware ordering logic, using the first pass indices as order key suffixes
130-
classDecriptors.sort(Comparator.comparing(classDescriptor -> {
130+
classDescriptors.sort(Comparator.comparing(classDescriptor -> {
131131
var secondaryOrderSuffix = firstPassIndexMap.get(classDescriptor);
132132
Optional<String> customOrderKey = getCustomOrderKey(classDescriptor, context, secondaryOrderSuffix)
133133
.or(() -> getCustomOrderKey(classDescriptor, context));

0 commit comments

Comments
 (0)