How to automate Kafka Testing

You can start Kafka programmatically in your integration test, Kafka uses Zookeeper so firsly look at Zookeeper TestingServer - instance of this class creates and starts the Zk server using the given port.

Next look at KafkaServerStartable.scala, you have to provide configuration that points to your in memory Zk server and invoke startup() method, here is some code:

import kafka.server.KafkaConfig; 
import kafka.server.KafkaServerStartable;
import java.util.Properties;

public KafkaTest() {
    Properties properties = createProperties();
    KafkaConfig kafkaConfig = new KafkaConfig(properties);
    KafkaServerStartable kafka = new KafkaServerStartable(kafkaConfig);
    kafka.startup();
}

Hope these help:)