I'm trying to integrate Testcontainers in my spring boot app. I'm using Kafka Container to allow sending Kafka messages. The main issue is that when I send message to kafka correctly, I would like to know what approach should be fine to validate if it was properly send. Because I don't want to include consumer part in my service in which is only producer.
I'm not mocking producer interface, so I'm not able to verify that method send was called. Thank you in advance
You simple can create a
KafkaTemplatein your unit test and use itsreceive()API: https://docs.spring.io/spring-kafka/reference/kafka/receiving-messages/template-receive.html. AConsumerFactorymust be provided into thatKafkaTemplate:Another option is to use
KafkaTestUtils.getOneRecord():However it doesn't sound like you use
spring-kafka-testmodule in your project.