0

I have written a kafka message listener like this.

@KafkaListener(groupId = "group", topics = "topic")
public void consume(String message) {
    log.info(message);
    serviceProcess.process(message);
}

    ServiceProcess{
    
    public boolean process(String str){
           //some logic here.
    }
    }

Write now I need to write the test case for this only. The problem is the jacoco is showing 0 coverage when I am using Embedded methodology. I have to write it in Mockito only.

  1. This is a void type of method.
  2. Test case should be in Mockito.
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Ravi Thapa
  • 79
  • 1
  • 7
  • Please, include your test code that's causing problems in your question. – Jonasz Aug 11 '22 at 14:37
  • @Jonasz, I wrote something like this ArgumentCaptor testCaptor = ArgumentCaptor.forClass(TestListener.class); Mockito.doAnswer(new Answer()-> { public Void answer(InvocationOnMock ivo) return null; }).when(testListener).consume(any()); – Ravi Thapa Aug 11 '22 at 17:59
  • 1
    For the code shown, you really only need to test your ServiceProcess methods. You don't need Kafka for that since there is no processing of the actual message event other than logging. – OneCricketeer Aug 11 '22 at 20:18
  • In that case it is showing 0 test coverage for the Listener method. – Ravi Thapa Aug 16 '22 at 10:22

0 Answers0