What Is Contract Testing?
Contract testing is a technique that verifies that two services (a consumer and a provider) can communicate correctly by testing each side independently against a shared contract that defines the expected request and response structure.
Free to start · 7-day trial on paid plans
In Depth
In a microservices architecture, services communicate via APIs. Integration testing verifies this by deploying all services together and testing end-to-end. This is expensive, slow, and brittle. Contract testing offers a lighter alternative: each service is tested in isolation against a contract that describes the API interface.
The most popular approach is consumer-driven contract testing (using tools like Pact). The consumer service writes tests that define what it expects from the provider (the contract). These expectations are published to a broker. The provider runs the contracts against its actual implementation to verify compatibility. If the provider changes an endpoint in a breaking way, the contract test fails before the change is deployed.
Contract testing does not replace integration testing but dramatically reduces the number of integration tests needed. You only need integration tests for scenarios that cross contract boundaries (data consistency, transaction behavior). Contract testing catches the most common integration issue (API shape mismatches) at a fraction of the cost.
Why Interviewers Ask About This
Contract testing is a key topic for microservices-heavy organizations. Interviewers ask about it to assess whether you can test distributed systems efficiently without over-relying on slow integration tests.
Example Scenario
A frontend team consumes a /users endpoint expecting {id, name, email}. The backend team renames "name" to "fullName." Without contract testing, this breaks in staging. With Pact, the consumer contract fails immediately when the provider runs verification, blocking the rename until the consumer is updated.
Interview Tip
Explain the consumer-driven contract testing workflow step by step. Mention Pact as the leading tool and discuss how contract testing complements (not replaces) integration testing.
Related Terms
Explore related glossary terms to deepen your understanding.
Related Resources
Dive deeper with these related interview prep pages.
Ready to Ace Your QA Interview?
Practice explaining contract testing and other key concepts with our AI interviewer.
Join 1,200+ QA engineers already practicing with AssertHired.
Start Your Free QA InterviewFree to start · 7-day trial on paid plans