hopsey
hopsey

Reputation: 1513

Spring cloud stream - integration tests, subscribers don't listen to events

I'm struggling with setting up integration test with spring cloud stream.

let's say I need to test the following integration flow

  1. Create an entity with POST request
  2. publish an event internally with message broker
  3. Collect the event within the same microservice and update the internal read model
  4. Make a GET request to the read model endpoint and check whether the read model has been updated

Updating read model works asynchronously. It works fine while running the app (events get collected and consumed), it does not work when I run integration tests. Method marked with @StreamListener simply does not get called while running tests, app doesn't event connect to message broker (kafka in my case)

I've used spring-cloud-stream-test-support and MessageCollector, but it gives me an opportunity to check whether an event was published and validate its payload.

What I need is to check whether the app has collected the event and reacted correctly to it.

What am I missing? Is there any sort of test binder that app subscribes to during test run?

Upvotes: 2

Views: 1308

Answers (1)

Gary Russell
Gary Russell

Reputation: 174729

When using the test binder, the test binder overrides the Kafka binder by default.

To run integration tests in the same project as the unit tests, you have to configure the test to use the real binder by excluding the TestSupportBinderAutoConfiguration.

For global exclusion, see the SCSt docs.

For exclusion in individual tests, see the Boot docs.

Finally, you can also control the list of auto-configuration classes to exclude by using the spring.autoconfigure.exclude property.

e.g. in @TestPropertySource.

Upvotes: 2

Related Questions