Interview frequency: …
Short answer
Contract tests independently verify compatibility between the consumer and provider API without running the entire distributed system in one test environment.
Explanation
In a microservices architecture, running 50 services together for E2E tests is slow, unstable, and expensive. Instead, in Consumer-Driven Contract Testing with tools such as Pact, a consumer test specifies what it expects from the provider in a JSON contract. The contract is sent to a Pact Broker, and the provider runs a test against it to verify compliance. If the provider changes a critical field that breaks the consumer, its build fails before release, without needing connected environments.
Code example
# Consumer side — what the client needs from GET /users/1
CONTRACT = {
"request": {"method": "GET", "path": "/users/1"},
"response": {"status": 200, "body": {"id": int, "fullName": str}},
}
# Provider side — verified in CI against the real API, no shared E2E environment required
def test_provider_honours_contract(client):
response = client.get(CONTRACT["request"]["path"])
assert response.status_code == CONTRACT["response"]["status"]
body = response.json()
for field, expected_type in CONTRACT["response"]["body"].items():
assert isinstance(body[field], expected_type)Common mistakes
- Relying on verbal assumptions or old manual documentation between frontend and backend teams, causing production failures during independent releases.