2

I would like to use MockAdminClient for unit testing my Kafka application. How can I make MockAdminClient imported using maven?

https://github.com/apache/kafka/blob/2.3.0/clients/src/test/java/org/apache/kafka/clients/admin/MockAdminClient.java

UPDATE:

My kafka-client related pom.xml

<dependency>
   <groupId>org.apache.kafka</groupId>
   <artifactId>kafka-clients</artifactId>
    <version>${kafka.version}</version>
</dependency>

By referring test by maven I found sth like this How can I reference unit test classes of a maven dependency in my java project?

Holm
  • 2,987
  • 3
  • 27
  • 48

2 Answers2

5

You need to pull the test classifier, and then add the test scope to get it only available for your unit tests

<dependency>
   <groupId>org.apache.kafka</groupId>
   <artifactId>kafka-clients</artifactId>
   <version>${kafka.version}</version>
   <classifier>test</classifier>
   <scope>test</scope>
</dependency>
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
-1

It is a part of Kafka Clients, you have to add the following dependency in maven pom.xml.

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.3.0</version>
</dependency>

For more dependencies, you can refer the below link. https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Sambit
  • 7,625
  • 7
  • 34
  • 65
  • 1
    I have the dependency in my pom, but MockAdminClient is in the test folder – Holm Jul 29 '19 at 15:31
  • Are you using multi module maven project ? – Sambit Jul 29 '19 at 15:35
  • no I will update my pom. I'm looking into sth like https://stackoverflow.com/questions/29653914/how-can-i-reference-unit-test-classes-of-a-maven-dependency-in-my-java-project – Holm Jul 29 '19 at 15:36