Course contentsShow
← Software Engineering
Lesson 550 of 1,93316. Integration TestingFree lesson

Consumer-Driven Contract Testing

Learning the consumer-driven approach where consumers define expected contracts that providers must satisfy.

Consumer-Driven Contract Testing

What you'll learn: How consumers define the contracts that providers must fulfill, flipping the traditional testing relationship.

The Consumer-Driven Approach

In traditional integration testing, the provider (the service or module being called) defines what it offers, and consumers must adapt. Consumer-Driven Contract Testing (CDC) reverses this dynamic: consumers explicitly state what they need from the provider, and those needs become contractual obligations the provider must satisfy.

Think of it like ordering a custom pizza. Instead of the restaurant deciding what's on the menu and you picking from it, you tell them exactly what pizza you want, and they commit to making it. Your order becomes the contract.

How It Works

Each consumer creates contract tests that specify:

  • Which endpoints or methods they call
  • What data they send
  • What response structure and data they expect

These consumer-defined contracts are collected and played against the provider. The provider must pass all consumer contracts to ensure compatibility. If Consumer A only uses two fields from an API response, its contract only specifies those two fields—the provider can change everything else without breaking that consumer.

Why Consumer-Driven?

This approach prevents provider breaking changes that consumers actually care about while giving providers freedom to evolve parts consumers don't use. It also surfaces consumer needs early—providers learn exactly how their API is being used, not how they think it's being used.

CDC shifts the conversation from "here's what I provide" to "here's what you need, and I promise to deliver it."

Key Takeaway: Consumer-Driven Contract Testing empowers consumers to define their expectations as executable contracts, ensuring providers meet real-world needs rather than assumed requirements.