From 1ed8eb08e0858e91152660278ffff15afd881b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Fri, 3 Oct 2025 16:32:11 +0200 Subject: [PATCH] Add missing Kotlin example for MockMvc and RestTestClient Closes gh-47371 --- .../withmockenvironment/MyMockMvcTests.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withmockenvironment/MyMockMvcTests.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withmockenvironment/MyMockMvcTests.kt index 2a09861c61d..18c92969fa1 100644 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withmockenvironment/MyMockMvcTests.kt +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withmockenvironment/MyMockMvcTests.kt @@ -24,6 +24,8 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.web.reactive.server.WebTestClient import org.springframework.test.web.reactive.server.expectBody import org.springframework.test.web.servlet.assertj.MockMvcTester +import org.springframework.test.web.servlet.client.RestTestClient +import org.springframework.test.web.servlet.client.expectBody @SpringBootTest @AutoConfigureMockMvc @@ -35,6 +37,15 @@ class MyMockMvcTests { .hasBodyTextEqualTo("Hello World") } + @Test + fun testWithRestTestClient(@Autowired webClient: RestTestClient) { + webClient + .get().uri("/") + .exchange() + .expectStatus().isOk + .expectBody().isEqualTo("Hello World") + } + // If Spring WebFlux is on the classpath, you can drive MVC tests with a WebTestClient @Test