Team A builds a frontend consuming Team B's API. Team B changes a response field from camelCase to snake_case. Both teams' unit tests pass. The integration environment is down. The change ships and the frontend breaks for every user. We have seen this at least twenty times.
Contract testing fills this gap. The consumer defines a contract: "I expect your API to return a JSON object with these fields and types." The provider verifies it satisfies all consumer contracts. Both sides run independently. Breaking changes fail before reaching production.
We use Pact, the most mature contract testing framework. The consumer phase: frontend tests define expected interactions. "GET /api/users/123 with valid auth should return 200 with id (number), name (string), email (string)." Pact records this as a contract file.
The provider phase: the backend runs the Pact verifier against their real API. It replays contract interactions and verifies responses match. Adding fields passes (additive changes are compatible). Removing or renaming fields fails.
Contracts live in Pactflow (hosted broker). When the frontend publishes a new contract, backend CI verifies automatically. When the backend deploys, it verifies against all consumer contracts first. Neither side can deploy breaking changes.
The speed advantage: our integration suite for one project took fourteen minutes spinning up five services. Contract tests covering the same surface run in twenty-three seconds. Consumer tests run against a mock server. Provider verification runs against a single service instance.
Contract testing verifies shape and format, not business logic. It confirms the API returns the right types but not correct values. You still need unit tests for logic and some integration tests for critical cross-service flows.
Setup: half a day for the first consumer-provider pair, two hours for additional pairs. Ongoing cost is minimal -- fast to write, fast to run, rarely flaky because they do not depend on network calls or shared state. One implementation detail that saves headaches: use provider states, named setup functions that prepare test data before verification.
About the Author
Fordel Studios
AI-native app development for startups and growing teams. 14+ years of experience shipping production software.
Enterprise load testing tools cost thousands per month. We use open source tooling and smart test design to answer the same questions for free.
A CSS change breaks the checkout button on mobile. No test fails because no test checks visual rendering. Visual regression testing catches these bugs automatically.
Startups cannot afford comprehensive test suites. They also cannot afford production bugs that lose customers. Here is how we maximize confidence per hour of engineering time.
We love talking shop. If this article resonated, let's connect.
Start a ConversationTell us about your project. We'll give you honest feedback on scope, timeline, and whether we're the right fit.
Start a Conversation