Pact: a consumer contract test between two services
Check the consumer’s real client against a mock, then check the real provider against the saved contract. Each result answers a different question.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: an order form between a shop and a baker. The shop says which loaf it needs. The baker checks whether its bread meets that need. The form leaves out details the shop does not use, such as the oven’s colour.
Mei tests Daily List, a made-up to-do app. Its phone app reads a task’s title. The tasks service plans to rename that field to name. Both names sound fine to a person. Code that still reads title may fail.
A contract test checks this agreement between programs. Mei first checks her phone app’s calling code against a controlled stand-in. This writes a file of its needs. Tom then checks the tasks service against that file.
These are two checks, not one. A passing phone test only shows it can use the stand-in’s reply. It does not show the changed service still sends that reply. Tom’s separate check supplies that evidence.
The picture has a limit: a written order does not inspect the baker. Nor does a saved contract test a running service by itself. These checks cover selected messages, not every user journey.
(SYNTHETIC / TRAINING ONLY: Daily List, Mei, Tom and all task data are invented.)
PLAIN WORDS · 1 in this section
- rename
- give a new name to
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB Check the real client against a stand-in, then the real provider against the saved needs.
- Expect
- Pact
- Verify
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The shop | The consumer |
| The baker | The provider |
| The order form | The pact file |
| Checking the form | Verification |
WHERE THIS PICTURE STOPS
- A form is read by people; Pact checks coded interactions and matching rules.
- A saved form proves no delivery. A pact file needs separate provider verification.
- A passed interaction is not proof of a whole journey or every deployed version.
HOOK
Expect, write, verify.
TELL A FRIEND
An order form: the shop writes it, the baker proves it.
OFTEN MIXED UP WITH Contract testing ideas. That topic gives the ideas. This one writes a consumer test and a provider check.
PRACTISE AND KEEP
Sources for this topic — 8 sources
- Market practice
How Pact works — consumer tests and provider verification ↗ — Pact Foundation · How Pact works: HTTP roles, Consumer testing, Provider verification and Putting it all together; page footer 23 December 2024. Actual primary page read 8 November 2026. Daily List is synthetic.
Opened relevant primary passages on6November2026 via normal web search and document view. Actual consumer client against mock provider, pact generation, independent provider states and provider verification opened. Product guidance, not a universal testing standard. Original figure source bytes matched repositorye2072af34960cb19d6c132d370c2fd580ec0e55c under the documentation MIT notice.
8 November 2026: actual HTTP interaction, Consumer Testing and Provider Verification sections through Putting It All Together opened, page footer 23 December 2024. Consumer checks and selected provider response verification are distinct; a written contract alone is not verification. No whole transport or deployed-behavior guarantee.
- Market practice
Writing consumer tests ↗ — Pact Foundation · Writing consumer tests: assertions, field-by-field exact/loose matching and isolated real client code. Actual primary page read 8 November 2026. Daily List is synthetic.
Named primary sections opened and read 8 November 2026. Product guidance, not a universal testing standard. Pact JS runtime behavior requires its separate executed test report. Provider API source: https://docs.pact.io/implementation_guides/javascript/docs/provider.
- Market practice
Verifying Pacts ↗ — Pact Foundation · Verifying Pacts: local provider, downstream stubbing below request parsing, and publishing versioned verification evidence. Actual primary page read 8 November 2026. Daily List is synthetic.
Named primary sections opened and read 8 November 2026. Product guidance, not a universal testing standard. Pact JS runtime behavior requires its separate executed test report. Provider API source: https://docs.pact.io/implementation_guides/javascript/docs/provider.
- Market practice
Using provider states effectively ↗ — Pact Foundation · Using provider states effectively: misleading one-record fixtures and contrasting data that exposes an ignored query parameter. Actual primary page read 8 November 2026. Daily List is synthetic.
Named primary sections opened and read 8 November 2026. Product guidance, not a universal testing standard. Pact JS runtime behavior requires its separate executed test report. Provider API source: https://docs.pact.io/implementation_guides/javascript/docs/provider.
- Market practice
Pact JS HTTP consumer and provider tests ↗ — Pact Foundation · Pact JS Consumer Tests and linked Provider Verification: Pact/PactV4, explicit specification version, executeTest, Verifier, stateHandlers and local pactUrls. Documentation read, not a runtime result. Actual primary page read 8 November 2026. Daily List is synthetic.
Named primary sections opened and read 8 November 2026. Product guidance, not a universal testing standard. Pact JS runtime behavior requires its separate executed test report. Provider API source: https://docs.pact.io/implementation_guides/javascript/docs/provider.
- Market practice
Can I Deploy ↗ — Pact project · Can I Deploy: version matrix, can-i-deploy with a target environment, and recording deployment after success. Actual primary page read 8 November 2026. Daily List is synthetic.
Primary page opened and read on 2026-10-21. Scope is the claim described here; this does not upgrade earlier citations to other pages. Examples in Daily List are synthetic teaching examples.
- Market practice
Pending pacts ↗ — Pact project · Pending pacts: a failed pending verification can leave the provider task green; the published result remains failed. No consumer compatibility pass follows. Actual primary page read 8 November 2026. Daily List is synthetic.
Primary page opened and read on 2026-10-21. Scope is the claim described here; this does not upgrade earlier citations to other pages. Examples in Daily List are synthetic teaching examples.
- Market practice
Pact JS HTTP process summary diagram ↗ — Pact Foundation / DiUS · Pact JS summary diagram (MIT licence, image unchanged) shown in this lesson: separate consumer and provider checks around a shared contract.
Original image and root MIT LICENSE read at pinned repository commit e50b6068ce9766a95ebfd678353a0e8057a0d8e6. Copyright and full permission notice retained beside the unchanged image. No endorsement claim. The earlier docs.pact.io figure was previewed but held because its license lived in a separate docs subtree.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.