diff --git a/integration-tests/main/src/test/java/io/quarkus/it/main/QuarkusTestNestedWithTestProfileTestCase.java b/integration-tests/main/src/test/java/io/quarkus/it/main/QuarkusTestNestedWithTestProfileTestCase.java new file mode 100644 index 0000000000000..ea34887a78915 --- /dev/null +++ b/integration-tests/main/src/test/java/io/quarkus/it/main/QuarkusTestNestedWithTestProfileTestCase.java @@ -0,0 +1,83 @@ +package io.quarkus.it.main; + +import static org.hamcrest.Matchers.is; + +import java.util.Collections; +import java.util.Map; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.QuarkusTestProfile; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; + +@QuarkusTest +@Tag("nested") +@TestProfile(QuarkusTestNestedWithTestProfileTestCase.OuterProfile.class) +public class QuarkusTestNestedWithTestProfileTestCase { + + private static final int TEST_PORT_FROM_PROFILE = 7777; + + @Nested + class NestedCase { + + @Test + void testProfileFromNested() { + Assertions.assertEquals(TEST_PORT_FROM_PROFILE, RestAssured.port); + RestAssured.when() + .get("/greeting/Stu") + .then() + .statusCode(200) + .body(is("OuterProfile Stu")); + } + } + + @Nested + @TestProfile(QuarkusTestNestedWithTestProfileTestCase.ModernEnglishProfile.class) + class ModernEnglishCase { + + @Test + void testProfileFromNested() { + RestAssured.when() + .get("/greeting/Stu") + .then() + .statusCode(200) + .body(is("Hey Stu")); + } + } + + public static class OuterProfile implements QuarkusTestProfile { + + @Override + public Map getConfigOverrides() { + return Collections.singletonMap("quarkus.http.test-port", "" + TEST_PORT_FROM_PROFILE); + } + + @Override + public String[] commandLineParameters() { + return new String[] { "OuterProfile" }; + } + + @Override + public boolean runMainMethod() { + return true; + } + } + + public static class ModernEnglishProfile implements QuarkusTestProfile { + + @Override + public String[] commandLineParameters() { + return new String[] { "Hey" }; + } + + @Override + public boolean runMainMethod() { + return true; + } + } +} diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java index 970242d209c98..3ec62a44e2ea8 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java @@ -184,12 +184,17 @@ protected PrepareResult createAugmentor(ExtensionContext context, Class getQuarkusTestProfile(ExtensionContext extensionContext) { - TestProfile annotation = extensionContext.getRequiredTestClass().getAnnotation(TestProfile.class); - Class selectedProfile = null; - if (annotation != null) { - selectedProfile = annotation.value(); + Class testClass = extensionContext.getRequiredTestClass(); + while (testClass != null) { + TestProfile annotation = testClass.getAnnotation(TestProfile.class); + if (annotation != null) { + return annotation.value(); + } + + testClass = testClass.getEnclosingClass(); } - return selectedProfile; + + return null; } protected static boolean hasPerTestResources(ExtensionContext extensionContext) {