beginnerTesting the Producer
Why is testing against an embedded/in-memory Kafka broker preferred over mocking the `KafkaTemplate` entirely?
Mocking `KafkaTemplate` only proves your code CALLED send() with the right arguments — it says nothing about serialization actually working, whether your message satisfies the topic's schema, or whether the producer config itself is valid. An embedded broker (or Testcontainers Kafka) runs real serialization and a real (if temporary) broker, catching a whole class of bugs mocks can't see.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.
Why is testing against an embedded/in-memory Kafka broker preferred over mocking the `KafkaTemplate` entirely?