I have just read articles about contract-based testing for verifying contracts between microservices:

In my company our team has built a REST service (A) that is used by other applications (B, C, D, ...) of other teams. I wonder how should we implement this idea. I envision the process like that:

  1. We provide other teams access to our test repository.
  2. Other teams, let say team of B, provide pull request w tests that test simulate behaviour of their application B against our contract A.
  3. We accept their pull request
  4. We run tests from other consumers (teams whose applications consume our service) as a part of our build.

My questions:

  • Is this correct understanding? Am I missing anything?
  • Is there any rule how consumer tests should look like? Should it be a real application B, C, D that calls our service or rather it should be a test that simulate those applications?
  • What are the tools supporting contract-based testing?

1 Answer 1


Here is how I have seen this implemented before:

  1. The consumer B produces a "B to A consumer contract file" that contains example requests and responses that it expects from A. B will contain a consumer test that produces this file and checks that B behaves correctly when it receives these expected responses from A.

  2. Each time B builds, it publishes the contract file and triggers an "A to B producer test". This test is owned by the producer A. The producer test uses the consumer contract file of B to verify that A behaves as B expects it to. This test is run against the following version combinations:

    • Latest A and Latest B
    • Latest A and Production B
    • Production A and Latest B
    • Production A and Production B

To answer your questions:

  1. You are missing that you need to verify more than just Latest A and Latest B if you want to be able to deploy A and B independently. You need to be confident that each time an application is built, it can be safely released, whether it is released first or last into production relative to the application it is a consumer/producer for.

  2. Two parts:

    • The consumer test should use the real consumer application with a simulated producer to test that the consumer behaves correctly when the producer behaves as the consumer expects

    • The producer test should use the real producer application with a simulated consumer to test that the producer behaves as the consumer expects.

  3. The only tool I can have personally used is pact-jvm

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.