Types of Contracts Testing – Consumer Driven, Provider Driven and Contract Driven

By Hari Krishnan

Share this page

The terms Contract Testing and “Consumer Driven Contract Testing” are often used interchangeably thereby making it seem like they are one and the same. However that is hardly the case. CDCT was largely popularised by Pact and it is a clever technique to learn. However there other types of contract also.

  1. Consumer / API Client
    • Creates a mock server to emulate the Provider / API / Service to make progress independent of the API / Provider
    • Generates API Contract based on this mock server – This is why it is known as Consumer Driven Contract
    • This Contract is shared with the Provider through a co-ordination / collaboration mechanism such as broker
  2. Provider / API
    • Runs the API Contract generated by the Consumer as a test against itself to verify if it (Provider) is behaving as per the Consumer’s expectation
    • It then publishes the verification result to the Consumers through the broker or other similar mechanisms
  3. Based on contract published by each consumer and corresponding verification status shared by the providers we can then determine if these consumers and providers can be deployed together

Here is a visual explanation of the same.

Pros

  1. Suitable for client first / client centric development style such as Backend For Frontend (BFF) where we start by building the client and only then build the provider
  2. In scenarios where many consumers are talking to a single provider, each consumer can generate the contract from its point of view
  3. Provides strong guarantees in identifying compatibility issues

Cons

  1. Sequential Style of Development – As you may have noticed, since the contracts are generated by the consumer, providers have to wait for consumers
  2. Consumer Bias in API Design – API design may become consumer centric since we are not necessarily starting with the API design or provider architecture in mind
  3. Learning curve and barrier for entry – IMHO Consumer Driven Contract Testing promotes good practices such as starting with the tests on consumer applications (especially the code first consumer driven contract testing approach of Pact), however this can also be a barrier for entry on some teams

Provider Driven Contracts

Spring Cloud Contract in “producer contract testing approach” leverages this technique (Spring Cloud Contract also supports Consumer Driven Contract Testing). Here is a brief summary of how this works.

  1. Provider / API
    • Creates the Contract and runs it as a test against itself to verify that it has satisfied the same
    • In the process it generates stubs that can emulate it (Provider)
    • These stubs are shared with Consumers through a mechanism such as artifact manager, broker, source control, etc.
  2. Consumer / API Client
    • Runs the stub servers shared by the provider to emulate the provider
    • Builds the client application with these stubs as reference
  3. Based on stubs published by providers and consumers being able to work with these stubs, we can determine if these consumers and providers can be deployed together

Pros

  1. Suitable for provider first / api centric development style such as public facing APIs, where we need not collaborate with the API consumers to design the API

Cons

  1. Sequential Style of Development – Since the contracts are created by the provider and the stubs are only generated as part of the providers verifying themselves against the contracts, consumers have to wait
  2. Provider Bias in API Design – API design is provider centric, Example: provider may under or oversupply information requiring consumers to do additional processing

Bi-Directional Contract Testing (BDCT)

Pactflow supports this approach where both consumers and providers have their own contracts. Please refer to the detailed explanation, use cases and tradeoffs.

Pros

  1. Suitable for many real world use cases such as Retrofitting Contract Testing to existing projects, etc.
  2. Consumer and Provider need

Cons

  1. Guarantees are not as strong as Consumer Driven Contract Testing

Contract Driven Development (CDD)

Contract Driven Development leverages API Specifications such as OpenAPI as Executable Contracts. Below is a visual explanation of how Specmatic embodies CDD.

Here is a quick explainer video.

Pros

  1. OpenAPI is your API Contract which means you only have a single source of truth for both API Specification and Contract, unlike other approaches
  2. Allows parallel development of consumer and provider
  3. Suitable for all styles of development such as Consumer First, Provider First and API First

Cons

  1. Discourages code generation – While this can be argued as a positive point, on teams that are accustomed to generating API Specifications and / or provider and consumer code from the API Specifications, authoring OpenAPI by hand can be a teething problem

Detailed comparisons between Contract Driven Development, CDCT, Provider Driven Contracts and BDCT

  1. Specmatic (CDD) vs Pact (CDCT) and Pactflow (BDCT)
  2. Specmatic (CDD) vs Spring Cloud Contract (Consumer Driven Contracts and Provider Driven Contracts)

Related Posts

mcp auto test meet specmatic mcp auto test

By Yogesh Nikam

Testing MCP servers: How Specmatic MCP Auto-Test Catches Schema Drift and Automates Regression

We recently shared a hands-on walkthrough with Specmatic where we explored practical approaches for Testing MCP servers, and in this post we want to expand
Read More
mcp auto test exposed mcp servers lying

By Yogesh Nikam

Exposed: MCP Servers Are Lying About Their Schemas

Table of Contents Practical Lessons from MCP Server Testing Over the last few weeks the Specmatic team ran a focused series of MCP server testing
Read More
specmatic genie mcp

By Jaydeep Kulkarni

Curate, Validate and Publish an MCP Server from an OpenAPI Spec with Specmatic Genie

In this walk-through we'll show exactly how we took the Postman APIs, curated the set of API end points we want to expose via MCP,
Read More
specmaticmcpdemo linkedin mcp

By Hari Krishnan

Specmatic MCP as guardrails for Coding Agents: API Spec to Full Stack implementation in minutes

Table of Contents In this walkthrough we'll show how to use Specmatic MCP server for API testing (Contract and Resiliency) and Mocking as a guardrail
Read More
arazzo openapi asyncapi demo with specmatic

By Hari Krishnan

Authoring & Leveraging Arazzo Spec for OpenAPI & AsyncAPI Workflow Testing

Seamlessly test both synchronous and asynchronous APIs in realistic workflows before they ever hit production! Discover how combining OpenAPI and AsyncAPI specs can simplify complex
Read More
Arazzo API workflow demo

By Hari Krishnan

Visual Workflow Mocking and Testing with Specmatic and Arazzo API Specifications

Table of Contents API workflow testing with Arazzo and Specmatic: Visual authoring, workflow mocking, and backend verification Here we'll walk through a practical approach to
Read More
Specmatic vs Microcks comparison

By Hari Krishnan

Specmatic vs Microcks

When evaluating tools for API testing and mocking, the choice often comes down to understanding not just what each tool can do, but how their
Read More
jaydeep aws lambda

By Jaydeep Kulkarni

AWS Lambda Data Pipeline Testing using LocalStack with Specmatic

Table of Contents Mastering Testing AWS Lambda Functions with LocalStack and Specmatic With fast-evolving data ecosystems, building reliable and scalable data products is essential. One
Read More
api days revised 1920x1080

By John

New features and a BIG Announcement! Specmatic is bringing apidays to India!

In the past few months, we have launched a flurry of exciting features, presented at several global conferences and onboarded several new team members. We
Read More
Speakers presenting on API Governance at tech conference.

Update: See how Specmatic is transforming API testing & development

We've been hard at work, rolling out exciting new features and sharing the power of Specmatic and Contract Driven Development around the globe! Let's explore
Read More