spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.75k stars 38.16k forks source link

Add testing utility for asserting SseEmitter events #33746

Open bclozel opened 1 month ago

bclozel commented 1 month ago

As seen in #33722, SseEmitter does not currently provide a way to perform assertions on published events for testing purposes. Our own testing infrastructure is leveraging protected methods to configure a test handler - we should consider providing a testing utility for this use case.

rstoyanchev commented 1 week ago

What about using MockMvc, and then check the output stream? Not at the same level of control, but MockMvc is lightweight (no server, nor full Spring config), and tests controllers more fully. In terms of testing items as they come, one at a time, one way or the other, the controller can't stream indefinitely, and has to be notified in some way to stop streaming, which makes it feasible to aggregate and check the response.