Spring Cloud Contract

Srinivas Kolaparthi
1 min readNov 16, 2022

Consumer-Driven Contracts are an approach to ensure service communication compatibility, in which the Consumer and Provider make an agreement about the format of the data they transfer between each other. This agreement forms the so-called Contract.

Normally, the format of the contract is defined by the Consumer and shared with the corresponding Provider. Afterward, tests are implemented in order to verify that the contract is being kept, called Contract Tests.

It is a project of spring-cloud that helps end-users in successfully implementing the Consumer Driven Contracts (CDC) approach. The Spring Cloud Contract Verifier is used as a tool that enables the development of Consumer Driven Contracts. Spring Cloud Contract Verifier is used with Contract Definition Language (DSL) written in Groovy or YAML.

Contract definitions are used to produce the following resources:

  • By default JSON stub definitions are to be used by WireMock (HTTP Server Stub) when doing integration testing on the client code (client tests). Test code must still be written by hand, and test data is produced by Spring Cloud Contract Verifier.
  • Messaging routes if you’re using one. We’re integrating with Spring Integration, Spring Cloud Stream, and Apache Camel. You can however set your integrations if you want to.
  • Acceptance tests (by default in JUnit or Spock) are used to verify if the server-side implementation of the API is compliant with the contract (server tests). The full test is generated by Spring Cloud Contract Verifier.

For more info: https://skolaparthi.com/spring-cloud-contract/



Srinivas Kolaparthi

I am a Trainer By Profession. I deliver DevOps, Microservices, Cloud, and Salesforce. Website: https://skolaparthi.com