title: Spring Boot with Kafka : How to write unit Integration tests excluding kafka configuration
body: <p>I am using <a href="https://mvnrepository.com/artifact/org.springframework.kafka/spring-kafka/2.2.6.RELEASE" rel="nofollow noreferrer">spring-kafka</a> dependency in my SpringBoot application to use Kafka. </p>
  
  <p>Everything works fine until my Kafka instance is up and running, but the problem is my <strong>unit&amp;integration</strong> tests, they run fine in my local but not in my deployment pipeline (<em>which is obvious since Application is trying to connect with Kafka instance [in my build pipeline] while running tests and unable to find any</em>), so end up getting following error :</p>
  
  <pre><code>[Consumer clientId=consumer-1, groupId=biz-web-group-test] Connection to node -1 
  could not be established. Broker may not be available.
  </code></pre>
  
  <p>This is only happening until I have a method annotated with <code>@KafkaListener</code> annotation </p>
  
  <pre><code> @KafkaListener(topics = "${biz-web.kafka.message.topic.name}", groupId = "${biz-web.kafka.message.group.id}")
   public void listenToKafkaMessages(ConsumerRecord consumerRecord) {
          // Some Logic
   }
  </code></pre>
  
  <p>As soon as I comment <code>//</code> this annotation, test cases work fine. </p>
  
  <p><strong>Is there a way I can exclude this kafka-related configuration or this annotation while running the unit/integration tests.</strong></p>