Sadly, this is not possible (anymore). I had such a test in my service as well and now, incrementing the Quarkus version to LTS 3.27.0, it is broken.
The test class cited in the answer from Holly Cummins (thanks for the link) is still present: QuarkusTestNestedWithTestProfileTestCase
However, there is a slight but important difference by now:
@Nested
@TestProfile(QuarkusTestNestedWithTestProfileTestCase.ModernEnglishProfile.class)
@Disabled("With the current test classloading design, test profiles on nested inner classes are too hard, because nested classes should run with the same classloader as the parent, but a test profile involves a new application, which involves a new classloader.")
class ModernEnglishCase {
@Test
void testProfileFromNested() {
RestAssured.when()
.get("/greeting/Stu")
.then()
.statusCode(200)
.body(is("Hey Stu"));
}
}
So bad luck here.
Executing my old and previously working test results in the following exception:
org.junit.jupiter.api.extension.TestInstantiationException: @Nested tests may not contain @TestProfile annotations.
at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted(QuarkusTestExtension.java:598)
at io.quarkus.test.junit.QuarkusTestExtension.beforeAll(QuarkusTestExtension.java:687)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
The behavior is as well documented here.
- Nested Tests
JUnit 5 @Nested tests are useful for structuring more complex test scenarios. However, note that it is not possible to assign different test profiles or resources to nested tests within the same parent class.