Collins21
Collins21

Reputation: 21

Unit Test KafkaMessageListenerContainer

Is it possible to unit test the KafkaMessageListenerContainer @Bean? I want to know if it is possible to conduct a put unit test on the code I use to construct the container. I'm trying to make sure that the container is getting built successfully.

However when I directly unit test the function that does this with a fake set of consumer Properties, I get an error that says

Failed to Construct Kafka Consumer.... No resolvable bootstrap urls given in bootstrap.servers

This error leads me to believe that this may not be possible to test in this manner. Is there another way to test this or is there a way to actually build the kafka message listener container and verify it with a unit test?

Upvotes: 1

Views: 543

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

It is attempting to start but it doesn't have configuration about which broker(s) to talk to (because of your dummy properties).

You can set its autoStartup property to false to prevent Spring from start()ing it.

You can use a property placeholder so the value is true for production and false for this test.

Upvotes: 1

Related Questions