Reference

API reference

The public test API, organised by task. Jump straight to the kind of test code you are writing.

Sections

Design notes

Shared-broker convenience

Where it makes sense, the API offers overloads that use the shared embedded broker internally:

Java
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 GenericRecord or SpecificRecord → Confluent Avro serialiser/deserialiser with mock schema registry
  • Protobuf Message (or DynamicMessage as a read target) → Confluent Protobuf serialiser/deserialiser with the same mock schema registry
  • Anything else (DTOs, POJOs) → Jackson 3 JSON serializer / deserializer
Java
// 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);