【发布时间】:2021-07-20 15:15:17
【问题描述】:
如 WebTestClient 的 javadoc 所述:This client can connect to any server over HTTP。
但是下面的代码并没有真正通过 http 请求:
@SpringBootTest(webEnvironment = DEFINED_PORT)
@AutoConfigureWebTestClient
public class HelloControllerTest {
@Autowired
WebTestClient webTestClient;
@Test
public void test_hello() {
webTestClient
.get()
.uri("http://localhost:8080/hello/World")
.exchange()
.expectStatus().isOk()
.expectBody()
.jsonPath("$.name").isEqualTo("aaa");
}
@Test
public void test_hello2() {
webTestClient = webTestClient.mutate().baseUrl("http://localhost:8080").build();// even this does not work
webTestClient.get()
.uri("/hello/World")
.exchange()
.expectStatus().isOk()
.expectBody()
.jsonPath("$.name").isEqualTo("aaa");
}
}
请帮助如何使用WebTestClient连接http服务器?
【问题讨论】:
标签: spring spring-webflux