java

Spring Cloud Contract

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. Afterwards, tests are being 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 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 own 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.

Spring Cloud Contract Verifier features:

  • Ensure that HTTP / Messaging stubs (used when developing the client) are doing exactly what actual server-side implementation will promote acceptance test driven development method and Microservices architectural style
  • To provide a way to publish changes in contracts that are immediately visible on both sides of the communication
  • To generate boilerplate test code used on the server side

Disadvantage:

  • To test one microservice we would have to deploy all microservices, a couple of databases, etc. 

Reference: https://spring.io/,https://skolaparthi.com/spring-retry/

Loading

Translate »