流式响应
你可以使用 WebTestClient
来测试 流式响应,例如 Server-Sent Events。然而,MockMvcWebTestClient
不支持无限流,因为无法从客户端取消服务器流。要测试无限流,你需要 绑定到一个 正在运行的服务器,或者在使用 Spring Boot 时,https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.with-running-server[使用正在运行的服务器进行测试]。
MockMvcWebTestClient
支持异步响应,甚至流式响应。其限制在于它无法影响服务器停止,因此服务器必须自行完成响应的写入。