Contract testing for Spring-boot apps (Part 1)

This is the first part of the series about contract testing for Spring-boot microservices apps.

Part 1: Introduction to Contract Testing

Part 2: Spring Cloud Contract Testing framework

Part 3: Contract Testing with Pact

Part 4: Contract Testing for GraphQl

Photo by Sebastian Herrmann on Unsplash

What is contract testing?

Contract testing is a set of automated tests that verify the interaction between two services (either through REST API or asynchronous message systems). It is different from unit and integration tests (which verify the operation within one service) and end-to-end test (which aims to validate the operation across UI and possibly multiple internal services).

For the purpose of this post, I'll only focus on contract testing for Rest API communication.


Contract testing centers around the concept of producer and consumer. More concretely, producer is the service that implementing the API endpoint while consumer invokes that endpoint. Thus, one producer can have multiple consumers and contract testing helps to ensure a change in the producer would not break any consumer's code.

Contract testing is a way to formalize the API specs (i.e how the request and response look like) between producer and consumer and better yet, this contract is verified for any change in consumer and provider's codebase.

Why is contract testing useful?


There are two big players in the contract testing space: Pact ( and Spring Cloud Contract ( In the next parts, I will implement a small PoC for each framework and discuss the advantages and disadvantages of each integration.

For further reading I can recommend the blog post here:

Product engineer / novice writer (

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store