diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java b/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java index 8521d7407200a..d5f606290bebe 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/TestResourceManager.java @@ -319,13 +319,15 @@ private Set uniqueTestResourceClassEntries(Path testClas * Allows Quarkus to extra basic information about which test resources a test class will require */ public static Set testResourceComparisonInfo(Class testClass, - Path testClassLocation) { + Path testClassLocation, List entriesFromProfile) { Set uniqueEntries = getUniqueTestResourceClassEntries(testClass, testClassLocation, null); - if (uniqueEntries.isEmpty()) { + if (uniqueEntries.isEmpty() && entriesFromProfile.isEmpty()) { return Collections.emptySet(); } - Set result = new HashSet<>(uniqueEntries.size()); - for (TestResourceClassEntry entry : uniqueEntries) { + Set allEntries = new HashSet<>(uniqueEntries); + allEntries.addAll(entriesFromProfile); + Set result = new HashSet<>(allEntries.size()); + for (TestResourceClassEntry entry : allEntries) { Map args = new HashMap<>(entry.args); if (entry.configAnnotation != null) { args.put("configAnnotation", entry.configAnnotation.annotationType().getName()); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java index 1dd9e846a844f..84f460e27704e 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java @@ -153,7 +153,8 @@ private QuarkusTestExtensionState ensureStarted(ExtensionContext extensionContex // we reload the test resources if we changed test class and if we had or will have per-test test resources boolean reloadTestResources = false; if ((state == null && !failedBoot) || wrongProfile || (reloadTestResources = isNewTestClass - && TestResourceUtil.testResourcesRequireReload(state, extensionContext.getRequiredTestClass()))) { + && TestResourceUtil.testResourcesRequireReload(state, extensionContext.getRequiredTestClass(), + selectedProfile))) { if (wrongProfile || reloadTestResources) { if (state != null) { try { diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java index 71776250160ec..107c2f9b60b81 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java @@ -67,7 +67,8 @@ private void ensurePrepared(ExtensionContext extensionContext, Class nextTestClass) { + static boolean testResourcesRequireReload(QuarkusTestExtensionState state, Class nextTestClass, + Class nextTestClassProfile) { + QuarkusTestProfile profileInstance = null; + if (nextTestClassProfile != null) { + try { + profileInstance = nextTestClassProfile.getConstructor().newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } Set existingTestResources = existingTestResources(state); - Set nextTestResources = nextTestResources(nextTestClass); + Set nextTestResources = nextTestResources(nextTestClass, + profileInstance); return TestResourceManager.testResourcesRequireReload(existingTestResources, nextTestResources); } @@ -54,9 +64,20 @@ static Set existingTestResources return Collections.emptySet(); } - static Set nextTestResources(Class requiredTestClass) { + static Set nextTestResources(Class requiredTestClass, + QuarkusTestProfile profileInstance) { + + List entriesFromProfile = Collections.emptyList(); + if (profileInstance != null) { + entriesFromProfile = new ArrayList<>(profileInstance.testResources().size()); + for (QuarkusTestProfile.TestResourceEntry entry : profileInstance.testResources()) { + entriesFromProfile.add(new TestResourceManager.TestResourceClassEntry(entry.getClazz(), entry.getArgs(), null, + entry.isParallel(), TestResourceScope.MATCHING_RESOURCES)); + } + } + return TestResourceManager - .testResourceComparisonInfo(requiredTestClass, getTestClassesLocation(requiredTestClass)); + .testResourceComparisonInfo(requiredTestClass, getTestClassesLocation(requiredTestClass), entriesFromProfile); } /** @@ -92,7 +113,7 @@ static List copyEntriesFromProfile( T instance = (T) testResourceClassEntryConstructor.newInstance( Class.forName(testResource.getClazz().getName(), true, classLoader), testResource.getArgs(), null, testResource.isParallel(), - Enum.valueOf(testResourceScopeClass, TestResourceScope.RESTRICTED_TO_CLASS.name())); + Enum.valueOf(testResourceScopeClass, TestResourceScope.MATCHING_RESOURCES.name())); result.add(instance); }