Browse Source

Add missing Kotlin example for MockMvc and RestTestClient

Closes gh-47371
pull/47395/head
Stéphane Nicoll 3 months ago
parent
commit
1ed8eb08e0
  1. 11
      documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/withmockenvironment/MyMockMvcTests.kt

11
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 @@ -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 { @@ -35,6 +37,15 @@ class MyMockMvcTests {
.hasBodyTextEqualTo("Hello World")
}
@Test
fun testWithRestTestClient(@Autowired webClient: RestTestClient) {
webClient
.get().uri("/")
.exchange()
.expectStatus().isOk
.expectBody<String>().isEqualTo("Hello World")
}
// If Spring WebFlux is on the classpath, you can drive MVC tests with a WebTestClient
@Test

Loading…
Cancel
Save