I’ve been searching a while about the best way to test Kafka in Spring. As far as I know, @EmbeddedKafka is more for an unit test but isn’t it better to test Kafka in a real working environment by writing integration test for it? And what really am I testing by writing unit test for Kafka? A real working producer and consumer should be more meaningful than mocking the kafka. What do you suggest?
EmbeddedKafka is an integration test. It starts a real broker, not a mock, for you to interact with.
For unit testing, Kafka provides its own mocks for consumer and producer, not reliant on Spring libraries
what really am I testing by writing unit test for Kafka
Your general processing logic, including error handling and deserialization
In Kafka Streams, you can also control the timing of the records for testing aggregation logic based on simulated windows