Streaming Responses

您可以使用 WebTestClient 来测试 streaming responses,例如 Server-Sent 事件。但是,MockMvcWebTestClient 不支持无限流,因为无法从客户端取消服务器流。要测试无限流,您需要启动 bind to 正在运行的服务器,或在使用 Spring Boot 时使用https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-testing-spring-boot-applications-testing-with-running-server[正在运行的服务器进行测试]。

MockMvcWebTestClient 支持异步响应,甚至支持流响应。它的限制是它不能影响服务器停止,因此服务器必须自行完成响应的编写。