Contract Test
ELI5 — The Vibe Check
A contract test checks that two services agree on how they'll talk to each other — what requests look like, what responses look like. If Service A changes its API, the contract test fails before Service B even knows about it. It's a handshake agreement backed by automation.
Real Talk
Contract testing verifies that service interfaces conform to a shared contract, enabling independent deployment of microservices. Consumer-driven contract testing (using Pact) lets consumers define expectations and providers verify they meet them, catching breaking changes before they reach production.
Show Me The Code
// Pact consumer test
const interaction = {
state: 'user exists',
uponReceiving: 'a request for user 1',
withRequest: { method: 'GET', path: '/users/1' },
willRespondWith: {
status: 200,
body: { id: 1, name: like('Alice') }
}
};
When You'll Hear This
"Contract tests let us deploy the auth service independently without breaking the API gateway." / "The contract test failed — the provider changed the response schema."
Related Terms
API Testing
API testing is checking that your backend endpoints work correctly — sending requests with different data and making sure you get the right responses, stat...
End-to-End Test (E2E)
An end-to-end test is like hiring a robot to be a user.
Integration Test
If a unit test checks one LEGO brick, an integration test checks that two bricks actually snap together correctly.