Consumer-driven contract testing

What ?

If we take a look at the definition of an integration test : “An integration test is a test between an API provider and an API consumer that asserts that the provider returns expected responses for a set of pre-defined requests by the consumer. The set of pre-defined requests and expected responses is called a contract.

This is the main focus of the approach : CONTRACTS.

The whole idea behind CDC is to involve consumers of the future API in the creation of the API itself. API changes will be driven by consumers.

Glossary :

  • Producer : Service that exposes an API.
  • Consumer : Service that consumes the API of the producer.
  • Contract : Agreement between producer and consumer on how the API will look like.
  • Consumer Driven Contracts : Approach where the consumer drives the changes of the API of the producer.

CDC

Why ?

In a micro-services world, testing the successful integration between services is critical for ensuring that the services won’t fail in production just because they’re not speaking the same language.

CDC is a solution to this.

How ?

  • Define API contract on the consumer side.

    Write Unit tests that define clearly what are the interactions and behaviors expected from the provider.

  • Enforce the contract on the service provider side.

    Unit tests on the provider side ensure that the provider implementation respect the expectations (contract) defined by the consumer.

To do it you can use a tool like pact :

CDC

Resources

Share this challenge