Contract Testing
Contract testing checks that two services which talk to each other, such as a web front end and an HTTP API, agree on the requests and responses they exchange. Each side is tested separately against a shared record of that agreement, so teams catch breaking changes without starting every service together in one test environment.
itSoftware engineering | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic: Contract Testing
Contract testing is a way to prove that two programs which talk to each other still agree on what they say, without switching both of them on in the same room. The one asking is the consumer. The one answering is the provider. The agreement between them is the contract, and it is written down so both sides can be checked against it separately.
Before this, teams had two options, each disappointing in its own way. The first was a unit test with a stand-in for the provider. That test is fast, but the stand-in only knows what the consumer team believes, and beliefs age badly. The second was an end-to-end test that starts everything at once. It proves more, at the price of a shared environment, slow runs, and the delicate job of getting every correct version in place simultaneously.
The first big idea is that the work splits into two halves that never meet. In the consumer build, your client code talks to a mock provider, a local fake that checks each request and returns the response you expected. Passing tests leave behind a pact file, a JSON record of every request and the smallest response your code needs. In the provider build, a verifier replays those requests against the real provider and checks that each answer contains at least what was asked for.
The second idea is that the contract is made of examples, not a complete schema. It covers only what consumers actually use. Extra fields in a response are ignored, so a provider can add things freely. Removing a field someone reads is what fails. Matching rules let a test say "any integer" instead of "exactly 10", which saves everyone from contracts that break over a changed ID.
The third idea is where the safety actually lives. A Pact Broker stores pact files and verification results and keeps a matrix of which consumer versions work with which provider versions. The can-i-deploy command asks that matrix whether a version is safe to release into an environment, and record-deployment tells it what went out afterwards. Skip either one and the pact files become paperwork.
The surprise is how little a contract promises. It checks the messages, not whether the provider did the right thing with them. An order request can match the contract perfectly while the order itself is saved wrong. Contract tests also suit teams who know their consumers and can talk to them; a public API with unknown consumers is outside the brief. Neither is a flaw. It is the price of being fast.
For the full model, from roles to pending pacts to other ways of writing the contract, read the intro. The slides compress it into flows and comparison tables. The cheatsheet holds matching rules, broker commands, and failure signals. If you prefer to find out by breaking something, the exercise has you write one contract, verify it, and then rename a field to watch verification fail.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://docs.pact.io/
Supports
- Definition of contract testing, consumer, provider, and contract
- Contract by example rather than schema
- Contract testing suits environments with many services
- https://docs.pact.io/getting_started/how_pact_works
Supports
- Consumer test against a mock provider and pact file generation
- Provider verification replay and minimal expected response
- Provider states
- Message pacts for non-HTTP communication, adapter and port separation
- https://docs.pact.io/getting_started/what_is_pact_good_for
Supports
- Conditions where Pact fits and where it fits poorly
- Public APIs, pass-through APIs, performance testing, uncontrollable provider data
- https://docs.pact.io/getting_started/matching
Supports
- Type, array, and regular expression matching rules
- Postel's law and ignoring unexpected response fields during verification
- https://docs.pact.io/getting_started/provider_states
Supports
- Provider states as preconditions set up by the provider
- Each interaction verified in isolation
- https://docs.pact.io/consumer/contract_tests_not_functional_tests
Supports
- Contract tests check messages while functional tests check side effects
- Validation-rule example of an over-specified contract
- https://docs.pact.io/consumer
Supports
- Use Pact for unit tests of the HTTP client class, not UI tests
- Use Pact as a mock, not a stub
- Fixed example values for generated data
- Include only data and operations the consumer uses
- https://docs.pact.io/provider
Supports
- Verify against a locally running provider in CI
- Stub only after the request is parsed and validated
- Publish verification results and use can-i-deploy
- https://docs.pact.io/faq
Supports
- Concrete examples instead of JSON Schema
- Verifying against deployed providers is discouraged
- https://docs.pact.io/faq/convinceme
Supports
- Contract tests compared with end-to-end integrated tests
- https://docs.pact.io/pact_broker
Supports
- Pact Broker purpose, REST API, matrix, webhooks
- PactFlow as a managed Pact Broker
- https://docs.pact.io/pact_broker/can_i_deploy
Supports
- can-i-deploy checks against versions already in the target environment
- The matrix of consumer and provider versions
- can-i-deploy and record-deployment command syntax
- https://docs.pact.io/pact_broker/recording_deployments_and_releases
Supports
- record-deployment and record-release semantics and syntax
- https://docs.pact.io/pact_broker/publishing_and_retrieving_pacts
Supports
- pact-broker publish command with version and branch
- https://docs.pact.io/getting_started/versioning_in_the_pact_broker
Supports
- Git commit SHA as application version and why
- https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors
Supports
- Recommended mainBranch, deployedOrReleased, and matchingBranch selectors
- https://docs.pact.io/pact_broker/webhooks
Supports
- contract_requiring_verification_published event behavior
- Webhooks for notifications on verification results
- https://docs.pact.io/pact_nirvana
Supports
- Staged CI/CD adoption guide
- https://docs.pact.io/blog/2020/02/24/how-weve-fixed-the-biggest-problem-with-the-pact-workflow
Supports
- Pending pacts and the provider-build problem they fix, 2020
- https://docs.pact.io/blog/2020/02/24/introducing-wip-pacts
Supports
- Work in progress pacts built on pending pacts, 2020
- https://docs.pact.io/blog/2021/07/04/why-we-are-getting-rid-of-tags
Supports
- Branches, environments, deployments, and releases replacing tags, 2021
- https://docs.pact.io/blog/2022/11/10/pact-plugin-framework-launch
Supports
- Pact Plugin Framework launch and supported technologies, 2022
- https://docs.pact.io/history
Supports
- Pact written at realestate.com.au in 2013 and origin of provider states
- https://docs.pact.io/blog
Supports
- Pact open source update channel used as an update source
- https://github.com/pact-foundation/pact-js
Supports
- PactV3, MatchersV3, executeTest, and Verifier usage
- Pact libraries for more than twelve languages
- Pact JS workshop as a hands-on tutorial
- https://github.com/pact-foundation/pact-js/blob/master/docs/matching.md
Supports
- integer and eachLike matchers
- https://github.com/pact-foundation/pact-js/blob/master/docs/provider.md
Supports
- stateHandlers, consumerVersionSelectors, enablePending, includeWipPactsSince, publishVerificationResult, providerVersionBranch
- https://github.com/pact-foundation/pact-workshop-js
Supports
- Hands-on Pact JS tutorial
- https://github.com/pact-foundation/pact_broker/releases
Supports
- Pact Broker release feed used as an update source
- https://martinfowler.com/bliki/ContractTest.html
Supports
- Contract tests check that test doubles match the real service, 2011
- https://martinfowler.com/articles/consumerDrivenContracts.html
Supports
- Provider, consumer, and consumer-driven contracts, 2006
- https://www.thoughtworks.com/radar/techniques/consumer-driven-contract-testing
Supports
- Consumer-driven contract testing in the Adopt ring, November 2015
- https://docs.spring.io/spring-cloud-contract/reference/getting-started/introducing-spring-cloud-contract.html
Supports
- Groovy and YAML contract DSL, generated producer tests, WireMock stubs
- Consumer-driven and producer-driven contracts
- https://spring.io/blog/2016/09/23/spring-cloud-contract-1-0-0-release-is-available/
Supports
- Spring Cloud Contract 1.0.0.RELEASE general availability, 2016
- https://spring.io/blog/2026/07/06/spring-cloud-contract-transition-to-stubbornsh/
Supports
- Transfer of Spring Cloud Contract to Stubborn.sh and removal from Spring Cloud release trains, July 2026
- https://github.com/spring-attic/spring-cloud-contract
Supports
- Spring Cloud Contract repository archived and no longer actively maintained
- https://stubborn.sh/
Supports
- Stubborn Contract as the official continuation, Apache 2.0 core, compatibility with existing contracts and stubs, commercial broker
- https://pactflow.io/bi-directional-contract-testing/
Supports
- Bi-Directional Contract Testing mechanism and PactFlow exclusivity
- https://pactflow.io/blog/introducing-bi-directional-contract-testing/
Supports
- Bi-Directional Contract Testing launch, March 2022
- https://pactflow.io/pricing/
Supports
- PactFlow free Starter tier
- https://pactflow.io/blog/the-case-for-contract-testing-protobufs-grpc-avro/
Supports
- Schema compatibility gives no semantic guarantee about fields consumers use
- https://smartbear.com/news/news-releases/smartbear-acquires-pactflow/
Supports
- SmartBear agreement to acquire PactFlow, April 2022
- https://specmatic.io/
Supports
- Specifications as executable contracts, stubs, and backward compatibility checks
- https://github.com/specmatic/specmatic
Supports
- Specmatic open source core under the MIT license
- https://microcks.io/
Supports
- Conformance testing and mocking from OpenAPI, AsyncAPI, gRPC, and GraphQL
- https://schemathesis.readthedocs.io/
Supports
- Property-based tests generated from OpenAPI or GraphQL schemas
- https://wiremock.org/
Supports
- HTTP stubbing server, record and playback, WireMock Cloud
- https://github.com/sindresorhus/awesome
Supports
- Discovery of the awesome-microservices list
- https://github.com/mfornos/awesome-microservices
Supports
- Testing tools curated for awesome links
- https://www.mbtest.dev/
Supports
- Imposters as multi-protocol test doubles
- https://docs.hoverfly.io/
Supports
- API simulation with recorded or custom responses
- https://www.mock-server.com/
Supports
- Mocking, proxying, and request verification
- https://keploy.io/
Supports
- Test cases and stubs generated from captured traffic
