Blog

Consumer-Driven Contract Tests: Verify The Fields Clients Actually Need

providers cannot guess every dependency
Several consumers publishing narrow expectations to one provider verification gate

Provider tests can prove its response matches a schema and still break a client that depends on one undocumented enum meaning.

Consumer-driven contracts record the interactions each consumer actually requires.

Keep Expectations Narrow

A consumer publishes request and response expectations with flexible matchers for irrelevant fields. The provider verifies them against real handler code and realistic state setup.

Do not assert a full response snapshot when the consumer reads two fields. Overspecified contracts freeze harmless evolution.

Contracts Do Not Replace Integration

They catch incompatible payload and interaction changes. They do not prove DNS, authentication deployment, network policy, database migration, or full workflow semantics.

Publish contract versions, associate them with deployable builds, and define whether a provider may deploy when an old consumer contract fails. The workflow is more important than the library.

State setup must also be part of the contract harness. A provider verification that mocks its handler returns proves only the mock. Seed the smallest realistic provider state and invoke the same serialization and routing path used by production, while keeping unrelated dependencies controlled.

Use contracts when teams deploy independently. Inside one modular monolith, a compile-time interface plus focused integration test may be simpler.

Contract Boundaries