Skip to content

Commit 1ed8eb0

Browse files
committed
Add missing Kotlin example for MockMvc and RestTestClient
Closes gh-47371
1 parent 49ba8aa commit 1ed8eb0

File tree

1 file changed

+11
-0
lines changed
  • documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withmockenvironment

1 file changed

+11
-0
lines changed

documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withmockenvironment/MyMockMvcTests.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import org.springframework.boot.test.context.SpringBootTest
2424
import org.springframework.test.web.reactive.server.WebTestClient
2525
import org.springframework.test.web.reactive.server.expectBody
2626
import org.springframework.test.web.servlet.assertj.MockMvcTester
27+
import org.springframework.test.web.servlet.client.RestTestClient
28+
import org.springframework.test.web.servlet.client.expectBody
2729

2830
@SpringBootTest
2931
@AutoConfigureMockMvc
@@ -35,6 +37,15 @@ class MyMockMvcTests {
3537
.hasBodyTextEqualTo("Hello World")
3638
}
3739

40+
@Test
41+
fun testWithRestTestClient(@Autowired webClient: RestTestClient) {
42+
webClient
43+
.get().uri("/")
44+
.exchange()
45+
.expectStatus().isOk
46+
.expectBody<String>().isEqualTo("Hello World")
47+
}
48+
3849
// If Spring WebFlux is on the classpath, you can drive MVC tests with a WebTestClient
3950

4051
@Test

0 commit comments

Comments
 (0)