Verify

Fluent assertions

Three flavours of assertion — for one record you already consumed, for the topic as a whole, and for collection-style queries over many records.

Overview

The assertion pages collect the fluent checks for Kafka records and topics. Use them when you want the test to read like the event contract instead of a chain of low-level polling and object comparisons.

Starting points

Use KafkaAssertions.assertThat(record) when your test has already consumed a record:

Java
assertThat(record)
    .hasKey("order-123")
    .hasJsonPath("$.status", "CREATED");

Use KafkaAssertions.assertThatRecord(...) when you want the assertion API to read one record from the shared broker:

Java
assertThatRecord("orders-topic", OrderEvent.class)
    .hasJsonPath("$.customer.id", "cust-42");

Use KafkaAssertions.assertThatTopic(...) when the topic contents are the subject of the test:

Java
assertThatTopic("orders-topic")
    .hasReadyListeners("orderListener")
    .records(OrderEvent.class)
    .inOrder()
    .containingExactly(
        r -> r.hasJsonPath("$.status", "CREATED"));