I have a producer application that needs unit testing. I don't want to spin up a Zookeeper and Kafka server for this purpose. Is there a simpler way to test it using Mockito?
If you don't want to start Kafka and Zookeeper, you can use the Mock clients that come with Kafka to fake sending and receiving messages from a Kafka cluster:
For such testing I've used EmbeddedKafka from the spring-kafka-test library (even though I wasn't using Spring in my app, that proved to be the easiest way of setting up unit tests). Here's an example : https://www.codenotfound.com/spring-kafka-embedded-unit-test-example.html
It actually spins up a Kafka and Zookeeper in the same process for you, so you're not really mocking anything out and so you don't need mockito for this. I used plain JUnit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With