Back

Introduction to Consumer-Driven Contract Testing: Understanding the Roles

If you are new to the concept of contract testing or looking at refreshing your knowledge this post is to describe the main components involved in building a contract test and understanding the responsibilities of the parties involved.

As more and more applications adopt a microservice architecture, we must adapt to be more efficient in testing these microservices. Contract testing can be used to check the compatibility between two different services early on in the development lifecycle and ensure that an understanding has been established between the members of the different teams building the dependent services.

As the schema for the microservices is undergoing changes during the development lifecycle, the contract test will ensure that no breaking changes are finding their way into the production environment.

Consumer-Driven Contract testing is driven by the microservice that will send the request and is dependent on the service that consumes the request. The owner of the contract will be the ‘consumer’, and the ‘provider’ will be running the tests to make sure that the contract is not broken. Creating a line of communication between the two services at a lower level of the testing pyramid instead of the End-to-End level which is a far costly test to find issues in.


When dealing with contract testing, there are three main components to remember:

  • Consumer: The consumer is the service that sends a request to the downstream service and is in charge of starting the contract testing process, for the consumer driven contract testing, by opening discussions with the provider team. The consumer will publish the pact which will contain the request(s) the consumer will send and the responses they expect.
  • Provider: This is the service that will be used by the consumer; the provider side is where the testing happens. If the provider service has introduced a change that violates the contract, the provider should not be allowed to build or package the service. Upon failure, the provider team will be forced to communicate the breaking changes to the consumer, establishing a new contract between the two teams or services and ensuring that no bugs find their way into production. After the new contract has been published by the consumer, the provider service may continue with the development cycle.
  • Pact Broker: The Pact contract has to be stored in a ‘neutral zone’ and not in either the consumer or provider repo. This is where the ‘broker’ comes in. The broker ensures full visibility of contracts and test results and provides a central location. The Pact Broker will host the Pact contract published by the Consumer and allow the Provider side to pull the contract during testing

References:

Test Pyramid Image: https://blog.octo.com/wp-content/uploads/2018/09/screen-shot-2018-09-11-at-12-00-21-pm-1024×630.png

Consumer Driven Contract Testing Image: https://docs.pact.io/

Abdula
Abdula
http://qabound.com