Reference
API reference
The public test API, organised by task. Jump straight to the kind of test code you are writing.
Sections
Core lifecycle
@EnableWiretapKafkaBroker, the JUnit extension, the Spring context initialiser, and the broker holder.
ReadAsync coordination
KafkaTestListeners, KafkaTestLatch, and KafkaTestAwait for listener readiness and CountDownLatch-based tests.
ReadReading records
KafkaTopicReader. Shared-broker overloads, typed auto-detection, custom deserialisers.
ReadPublishing records
KafkaTestPublisher. Shared-broker overloads, typed auto-detection, batch APIs, headers.
ReadAssertions API
KafkaAssertions, KafkaRecordAssert, KafkaTopicAssert, KafkaRecordsAssert, and KafkaChoreographyAssert.
Read
Design notes
Shared-broker convenience
Where it makes sense, the API offers overloads that use the shared embedded broker internally:
KafkaTestPublisher.send("orders-topic", "order-123", "created");
ConsumerRecord<String, String> record =
KafkaTopicReader.readSingleRecord("orders-topic");Auto-detection (v2)
In v2, the library detects the serialisation format automatically from the value type or target class. There are no longer separate sendJson, sendAvro, readJsonRecords, or readAvroRecords methods.
String→StringSerializer/StringDeserializer- Avro
GenericRecordorSpecificRecord→ Confluent Avro serialiser/deserialiser with mock schema registry - Protobuf
Message(orDynamicMessageas a read target) → Confluent Protobuf serialiser/deserialiser with the same mock schema registry - Anything else (DTOs, POJOs) → Jackson 3 JSON serializer / deserializer
// JSON DTO — auto-detected
KafkaTestPublisher.send("orders-topic", orderId, orderDto);
ConsumerRecord<String, OrderEvent> record =
KafkaTopicReader.readSingleRecord("orders-topic", OrderEvent.class);
// Avro SpecificRecord — auto-detected
KafkaTestPublisher.send("trades-topic", tradeId, tradeEvent);
ConsumerRecord<String, TradeEvent> record =
KafkaTopicReader.readSingleRecord("trades-topic", TradeEvent.class);