I tried to switch our application to use Async Events. Now our event publisher tests fail. I found a few posts mentioning this https://github.com/spring-projects/spring-framework/pull/30020
So with current versions of Spring(Boot) this should be fixed, but it still doesn't work. We are using SpringBoot 3.4.1
@SpringBootTest
@RecordApplicationEvents
class MyEventPublisherTest {
@Autowired private ApplicationEvents events;
@Autowired private MyEventPublisher testSubject;
@BeforeEach
void setUp() {
events.clear();
}
@Test
void validPayload_publishEvent_eventCreated() {
// given
final MyId id = MyId.fromUuid(UUID.randomUUID());
final MyPayload payload = MyPayload.create(id);
// when
testSubject.publishEvent(payload);
// then
assertThat(events.stream(MyPayloadEvent.class).count()).isEqualTo(1);
}
}
Do I need to add some additional annotations or configurations to the test? This test fails with there were 0 events. This works with synchronous events.