Keploy logo
Apache Kafka logo

Keploy as a Apache Kafka testing framework

Keploy tests Kafka producers and consumers by recording the broker protocol beneath your client, capturing produce acknowledgements, fetch responses, and offset commits, then replaying them during tests. No broker or ZooKeeper runs in CI and no embedded cluster is started.

Generate Apache Kafka tests free
keploy record -c "java -jar orders.jar"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a Apache Kafka team

Captured at the Kafka broker protocol

Keploy reads the protocol beneath your client, recording produce requests with the broker's acknowledgement and fetches with the records returned and the offset committed.

  • Below KafkaProducer, kafkajs, sarama, confluent-kafka
  • Produce acknowledgements with real offsets
  • Fetch responses and offset commits
  • Partition assignment preserved
The problem

Why Apache Kafka integration tests slow teams down

The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.

Three ways to do it

Testing Apache Kafka: by hand, with EmbeddedKafka / Testcontainers, or with Keploy

An embedded or containerised broker gives real Kafka semantics and makes every test timing-dependent, because it must poll for messages that arrive asynchronously. Replay removes the asynchrony.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for Apache Kafka vs what Keploy records

All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.

By hand2–4 hours
OrderEventsFakeTest.java
hand-written
// Hand-written fake: nothing is serialised or partitioned.
package com.acme.orders;
 
import java.util.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
 
class FakeEventPublisher implements EventPublisher {
final List<Object> published = new ArrayList<>();
 
@Override
public void publish(String topic, Object event) {
// No serialiser runs. No partition is chosen. No ack returns.
published.add(event);
}
}
 
class OrderEventsFakeTest {
 
@Test
void publishesAConfirmedEvent() {
var publisher = new FakeEventPublisher();
new OrderService(publisher).confirm("ord_1");
 
assertEquals(1, publisher.published.size());
}
}

This asserts that a method was called. A serialiser misconfiguration or a wrong partition key would pass this test and break in production.

EmbeddedKafka / Testcontainers1–2 hours
OrderEventsEmbeddedTest.java
tool-assisted
// EmbeddedKafka: a real broker, started per test class.
package com.acme.orders;
 
import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.springframework.kafka.test.context.EmbeddedKafka;
 
@EmbeddedKafka(partitions = 1, topics = "orders.confirmed")
class OrderEventsEmbeddedTest {
 
@Test
void publishesAConfirmedEvent() {
service.confirm("ord_1");
 
// Poll until it shows up, or give up. This is the flaky part.
var records = consumer.poll(Duration.ofSeconds(10));
 
assertEquals(1, records.count());
var record = records.iterator().next();
assertEquals("ord_1", record.key());
}
}

Real serialisation and real partitions, at the cost of a broker start per class and a ten-second poll window that turns CI load into test failures.

With Keploy~5 minutes
mocks.yaml
auto-generated
# Recorded with: keploy record -c 'java -jar orders.jar'
# The broker exchange, captured at the wire protocol.
version: api.keploy.io/v1beta1
kind: Kafka
name: mock-5
spec:
produce:
topic: orders.confirmed
partition: 0
key: "ord_1"
# The bytes your configured serialiser actually produced.
value_serialized: "eyJpZCI6Im9yZF8xIiwic3RhdGUiOiJDT05GSVJNRUQifQ=="
headers:
content-type: "application/json"
# The real acknowledgement from the broker.
response:
base_offset: 4127
error_code: 0
fetch:
topic: orders.confirmed
partition: 0
committed_offset: 4128

The serialised bytes and the broker's real offset acknowledgement are both recorded, so serialiser and partition-key bugs surface as diffs — with no polling and no timeout.

Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.

Keploy vs the alternatives

Apache Kafka testing tools, compared

The options a team on message brokers actually reaches for, and where each one genuinely wins. Select a row for the full comparison.

Best in classStrongPartialNot covered

Assessments reflect each tool’s documented behaviour, not benchmark measurements.

How it works

Record your Apache Kafka app once, replay it forever

Keploy sits below your Apache Kafka process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.

Keploy records a GET call to /api/v1/orders/{id} on a Apache Kafka service and captures the dependency calls it makes.

Apache Kafka logo
Your Apache Kafka app
GET/api/v1/orders/{id}200
RecordingKeploy proxyeBPF · userspace
+2 more Apache Kafka clients
An example shape of a captured call. Your own endpoints and dependencies come from your real traffic, so nothing here has to be written by hand.
Mock coverage

Apache Kafka clients Keploy records, driver by driver

Keploy captures Apache Kafka at the wire protocol, so 5 of these 8 clients need no adapter, no test double, and no Apache Kafka instance in CI.

Quick start

Your first Apache Kafka test suite in under five minutes

Every command below runs against your existing Apache Kafka service. Nothing in your source tree changes.

  1. 1Install the Keploy CLI

    One binary on the recording machine. Nothing is installed into the broker and no client wrapper is needed.

    curl -sSL https://keploy.io/install.sh | bash
  2. 2Record with your development broker reachable

    Run the app as usual. Produce requests, acknowledgements, fetches, and offset commits are all captured in order.

    keploy record -c "java -jar orders.jar"
  3. 3Exercise both sides of the topic

    Trigger the endpoint that produces, then let your consumer process the message so both halves are recorded.

    curl -X POST localhost:8080/orders/ord_1/confirm -d '{"paymentToken":"tok_123"}'
  4. 4Replay with the broker stopped

    Shut Kafka down and run the suite. Replay is deterministic, so there is no poll timeout to tune.

    keploy test -c "java -jar orders.jar" --delay 20

Ready to try it on your own Apache Kafka service?

Ecosystem

Works with the rest of your Apache Kafka stack

Keploy records at the network layer, so framework and driver choices inside your Apache Kafka app do not change how it captures traffic.

FAQ

Apache Kafka testing with Keploy: common questions

Join our GlobalCommunity

Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.

1.2M+Installs
18.4K+GitHub
100K+Devs
300M+Mocks
1K+Contributors
#1OSS Trending
4.9★★★★★from 500+ reviews onG2GartnerVS CodeChrome
★★★★★

Best report of integration and API tests I've seen — which we don't get from RestAssured.

G2
★★★★★

Future of microservices testing. I don't write tests now!

G2 · 5/5
★★★★★

An amazing product that simplifies the automation.

Gartner · 4.0
XGitHubSlackYouTubeLinkedIn
Built by developers, for developers.Let's build the future, together.