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.

Comment From: rstoyanchev

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.

Comment From: bclozel

Closing this because of Rossen's suggestion. @kkocel please let us know if the suggested approach doesn't work and why.

Comment From: kkocel

@rstoyanchev @bclozel, the main issue for me is speed. I've created https://github.com/kkocel/spring-framework-33746 to compare two testing approaches. Using MocMvc is an order of magnitude slower than using unit tests. That's why I believe it should be possible to test SSE events directly.

org.springframework.web.servlet.mvc.method.annotation.EventGeneratorUnitTest

  Test shouldHandleEvents() PASSED (35ms) <- unit test

com.example.springframework33746.EventGeneratorWebMvcTest

  Test shouldGetSseEvents() PASSED (451ms) <- mock mvc test