Skip to main content

Avro Assertions

Avro matchers deserialise GenericRecord values (via Schema Registry) and compare them as JSON or by individual fields.


File match : Then expected record from file based on schemaโ€‹

Fetches an Avro record, converts it to JSON, and compares it against an expected JSON file. Excludes specified top-level keys from comparison.

Then expected record from file based on schema
| topicAlias | file | excludedKeys | consumerReadTimeout |
| orders-out | expected.json | createdAt,eventId | 30 |
ColumnTypeRequiredDescription
topicAliasstringโœ…Alias of a declared output topic
filestringโœ…Expected JSON file path, relative to assets directory
excludedKeysstringโŒComma-separated list of Avro field names to ignore during comparison
expectedRecordKeystringโŒFilter: only accept records with this exact key
consumerReadTimeoutintegerโŒMax seconds to wait for a record
consumerDeltaTimeintegerโŒHow far back (seconds) to seek

Key + file match : Then expected record with key and value from file based on schemaโ€‹

Asserts both the record key and value (as Avro โ†’ JSON) against a file.

Then expected record with key and value from file based on schema
| topicAlias | file | excludedKeys |
| orders-out | expected.json | timestamp |

Field value match : Then expected record based on schema should have fields matching from given valueโ€‹

Asserts one or more specific Avro field values without a file.

Then expected record based on schema should have fields matching from given value
| topicAlias | key | value |
| orders-out | status | PROCESSED |
ColumnTypeRequiredDescription
topicAliasstringโœ…Alias of a declared output topic
keystringโœ…Avro field name
valuestringโœ…Expected field value (string-compared after JSON serialisation)

Key match : Then expected Avro record should match keyโ€‹

Asserts only the record key; the Avro value is ignored.

Then expected record based on schema should match key
| topicAlias | expectedRecordKey |
| orders-out | ord-001 |

Positional fields : Then expected record based on schema should have fields matching from fileโ€‹

Assert a specific character range of the JSON-serialised Avro value.

Then expected record based on schema should have fields matching from file
| topicAlias | file | line | from | to |
| orders-out | expected.txt | 1 | 0 | 10 |

See alsoโ€‹