How Pact contract testing works

PactFlow allows developers and their teams to use contract testing with Pact and other contract types (such as OpenAPI).

The problem with integration tests

Why not use isolated tests?

How Pact helps - the consumer side

How Pact helps - the provider side

How Pact helps

Sharing the contracts and CI/CD integration

Testing a request between two deployed applications

Testing a request using simulated applications

Testing a request using simulated applications

Testing a consumer using a Pact mock provider

Testing a consumer using a Pact mock provider

Testing a provider using a Pact simulated consumer

Testing a provider using a Pact simulated consumer

Testing a request with Pact

Collaborating on contracts

Before we deploy an application to production, we need to be sure it works correctly with the other applications with which it integrates. To do this, traditionally we run integration tests using "live", deployed applications.

Integration tests

  • give us confidence to release

but

  • introduce dependencies
  • give slow feedback
  • break easily
  • require lots of maintenance

Replay Replay animation

By testing each side of an integration point using a simulated version of the other application, we get two sets of tests which

  • run independently
  • give fast feedback
  • are stable
  • are easy to maintain

but

  • do not give us confidence to release.

This is because there is nothing to ensure that the simulated applications behave the same way as the real ones.

Replay Replay animation

Pact solves the problem of keeping the two sets of tests in sync by use of a "contract", also known as a "pact".

During the consumer tests, each request made to a Pact mock provider is recorded into the contract file, along with its expected response.

Replay Replay animation

A Pact simulated consumer then replays each request against the real provider, and compares the actual and expected responses. If they match, we have verified that the simulated applications behave the same way as the real applications. This means the two real applications should communicate correctly when they interact in real life.

Replay Replay animation

Using Pact gives you tests that

  • run independently
  • give fast feedback
  • are stable
  • are easy to maintain

and

  • give you confidence to release

Once you have contract tests in place, you need a process to manage your contract testing process. This is where the Pact Broker comes in. The Pact Broker enables you to:

  • Share and collaborate on contracts across teams
  • Manage contracts across code branches and environments
  • Orchestrate builds to know when it is safe to deploy
  • Integrate into your processes and tooling

You can use PactFlow's hosted platform which takes care of hosting, related maintenance, security, team management and more.

PactFlow's free Starter Plan is a great way to kick-start a rapid proof of concept.

Previous Back
Forward Next
arrow-up icon