diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc index d6224f8de50..71ecd3e84b3 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc @@ -451,11 +451,14 @@ Often, javadoc:org.springframework.boot.graphql.test.autoconfigure.GraphQlTest[f include-code::GreetingControllerTests[] javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] tests are full integration tests and involve the entire application. -When using a random or defined port, a live server is configured and an javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean is contributed automatically so you can use it to test your server. -When a MOCK environment is configured, you can also request an javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean by annotating your test class with javadoc:org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester[format=annotation] from the `spring-boot-graphql-test` module: +A javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean can be added by annotating your test class with javadoc:org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester[format=annotation] from the `spring-boot-graphql-test` module: include-code::GraphQlIntegrationTests[] +The javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean uses the relevant transport of the integration test. +When using a random or defined port, the tester is configured against the live server. +To bind the tester to `MockMvc`, make sure to annotate your test class with javadoc:org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc[format=annotation]. + [[testing.spring-boot-applications.autoconfigured-spring-data-cassandra]] diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.java index f5259e01647..28acb612383 100644 --- a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.java +++ b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.java @@ -21,10 +21,11 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.graphql.test.tester.HttpGraphQlTester; +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @AutoConfigureHttpGraphQlTester -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) class GraphQlIntegrationTests { @Test diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.kt index c6ceda46360..2c1df1ac24a 100644 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.kt +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/springgraphqltests/GraphQlIntegrationTests.kt @@ -20,12 +20,13 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment import org.springframework.graphql.test.tester.HttpGraphQlTester import org.springframework.http.HttpHeaders import org.springframework.test.web.reactive.server.WebTestClient +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @AutoConfigureHttpGraphQlTester -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) class GraphQlIntegrationTests { @Test diff --git a/module/spring-boot-graphql-test/src/main/java/org/springframework/boot/graphql/test/autoconfigure/tester/AutoConfigureHttpGraphQlTester.java b/module/spring-boot-graphql-test/src/main/java/org/springframework/boot/graphql/test/autoconfigure/tester/AutoConfigureHttpGraphQlTester.java index 57290ec69bb..9da30c3f2f8 100644 --- a/module/spring-boot-graphql-test/src/main/java/org/springframework/boot/graphql/test/autoconfigure/tester/AutoConfigureHttpGraphQlTester.java +++ b/module/spring-boot-graphql-test/src/main/java/org/springframework/boot/graphql/test/autoconfigure/tester/AutoConfigureHttpGraphQlTester.java @@ -24,7 +24,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; import org.springframework.boot.webtestclient.AutoConfigureWebTestClient; import org.springframework.graphql.test.tester.HttpGraphQlTester; @@ -39,7 +38,6 @@ import org.springframework.graphql.test.tester.HttpGraphQlTester; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@AutoConfigureMockMvc @AutoConfigureWebTestClient @ImportAutoConfiguration public @interface AutoConfigureHttpGraphQlTester { diff --git a/smoke-test/spring-boot-smoke-test-graphql/src/test/java/smoketest/graphql/GreetingControllerTests.java b/smoke-test/spring-boot-smoke-test-graphql/src/test/java/smoketest/graphql/GreetingControllerTests.java index ea8a6d0f3a4..bf264df0e73 100644 --- a/smoke-test/spring-boot-smoke-test-graphql/src/test/java/smoketest/graphql/GreetingControllerTests.java +++ b/smoke-test/spring-boot-smoke-test-graphql/src/test/java/smoketest/graphql/GreetingControllerTests.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; import org.springframework.graphql.execution.ErrorType; import org.springframework.graphql.test.tester.HttpGraphQlTester; @@ -28,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest @AutoConfigureHttpGraphQlTester +@AutoConfigureMockMvc class GreetingControllerTests { @Autowired