What’s up Guys! Welcome to automationcalling.com

This post is a continuation of the blog Contract Test + Spring Boot for Microservices Architecture.

In my previous blog regarding the contract test, there was a challenge to maintain the consumer test pact file under the resource folder which is pre-requisites to run the provider test.

In reality, some challenges are:

  • The Consumer and Provider of API may be a different team in the same organization
  • The Consumer and Provider of API may be different companies
  • The Consumers of API may be consumed different versions and different features

To address all these challenges, PACT Broker is the solution. In case, if you are looking for plug and play option, please visit PACTFLOW, This is fully managed pact broker on SAAS Platform which is licensed.

What are the advantages of PACT Broker?

  • Solves the communication problem and share a common understanding and verify results quickly.
  • Avoid bottleneck of integration test and Deploy your service quickly with more confidence.
  • This will provide API documentation for your Application that’s up-to-date.
  • Visualized representation and show you how your real service interact.
  • Version management and backward compatibility for multiple consumers.

PACT Broker Features:

  • REST API Support
  • Automatic documentation for each PACT
  • Automatic/Dynamic generation of a network diagram for your deployed microservice architecture.
  • Verify results based on Provider Test
  • Provides WebHook status that triggers an action when PACT changes. For eg., this can be notified in Slack Channel or email, etc.,
  • View Diff for failure results between Consumer and Provider test

In this blog, we are going to take a look at how to set up the PACT Broker using Docker and Run Provider Test.


  • Docker community edition version 19 and above must be installed.
  • Docker compose file must be ready (This will be covered in the below blog)

Docker Compose File:

Save the below content as docker-compose.yml file and feel free to change ports, username, and password for Postgres and pact broker.

version: '3'
    image: postgres
      test: psql postgres --command "select 1"
      - "5432:5432"
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgressdb
      POSTGRES_DB: postgres

    image: dius/pact-broker
      - "9080:80"
      - postgres

After saving the file, Go to the directory where the file is saved.

Supply the following command:

docker-compose up -d

After the command, the server gets started and display as below snapshot.


Time to Run Consumer Mock Test:

To publish your consumer mock test in Pack broker, you need to add the following plugin in pom.xml

    <!-- mvn pact:publish  -->
        <pactDirectory>${project.build.directory}/pacts</pactDirectory> <!-- Defaults to ${project.build.directory}/pacts -->
        <projectVersion>${project.version}</projectVersion> <!-- Defaults to ${project.version} -->
        <trimSnapshot>true</trimSnapshot> <!-- Defaults to false -->
  • The very first step is to run all your consumer tests so that the pact files for your tests will be resided under target/pacts/
  • The second step is to publish the results to PACT broker which you need to supply the following commands
    • mvn pact:publish

After running the maven command, the result should display as below snapshot.



If you look at the above snapshots, the consumer mock test is documented and display on pact broker, this will help to provide better communication regarding how API is to be consumed and provider suppose to get respond.

Time to Run Provider Test Against Pact Broker:

To run the provider test against Back Broker, the following plugin is required on pom.xml

    <!-- mvn pact:verify  -->
            <!-- You can define as many as you need, but each must have a unique name -->
                <!-- All the provider properties are optional, and have sensible defaults (shown below) -->

In the above plugin, you need to mention the following:

  • Provider Test Name
  • Provide Host, Port where your Back Broker is running

Provider Test:

public class ProviderVerification {
    @State("Test GET Request")
    public void toGetState() {

    public final Target target = new HttpTarget(8080);


After that, supply the following command in maven to run provider test

  • mvn pact:verify

This will connect the Consumer Mock test on the PACT broker, by using that, it will run the test against real service (Hitting API endpoints) and compare response results between Real Service and Mock Service as shown in the below snapshot.


Refresh the page in PACT broker, which will reflect green status indicates contract test is verified and success


Please use my existing  GitHub which has Spring Boot Application and doesn’t have a PACT broker setup. I think it’s good for you guys to play around on this by following the above steps. For an example test, remember you need to start “EmployeeApp” first

Thanks for your time, please do subscribe for more updates!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s