Skip to content

Contract Test

Medium — good to knowTesting

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.