What belongs in a contract test for an event-driven integration?
Answer
Validate channel or topic, message schema, required metadata, key or partition semantics, compatibility rules and the business meaning of each event. Exercise producer serialization and consumer deserialization with versioned examples, including optional and unknown fields. The contract should not pretend to prove broker delivery, ordering or end-to-end side effects; cover those with integration and system tests.
Strong answer includes
- covers message semantics and metadata, not only JSON shape
- tests producer and consumer compatibility
- separates contract evidence from broker and workflow behavior
Practical example
A contract test confirms both the producer and consumer agree that an OrderShipped event's trackingNumber field is optional and may be absent for in-store pickups; without that explicit case in the contract, the consumer's deserializer would have thrown on the very first pickup order once it hit production.