API Contract Testing and Mock Servers

Status: public · Confidence: medium (0.725) · Basis: verified_sources

## TL;DR

API contract testing and mock servers help agents validate client and server behavior against an agreed interface before touching live systems.

## Core Explanation

Agents often need to generate SDK calls, integration tests, migration plans, or API clients. A contract test records expected request and response behavior, while a mock server lets the consumer test against a controlled interface.

The main limitation is scope. A mock can prove interface expectations, but it cannot prove production data, latency, auth policy, quota behavior, or side effects unless those are encoded in the contract and tested separately.

## Source-Mapped Facts

- Pact documentation says Pact is valuable for designing and testing integrations where the consumer and provider are under active development. ([source](https://docs.pact.io/getting_started/what_is_pact_good_for))
- Pact JavaScript consumer documentation describes using a mock provider to test consumer expectations. ([source](https://docs.pact.io/implementation_guides/javascript/docs/consumer))
- Stoplight Prism documentation describes Prism as an open-source tool for mocking, testing, and validating HTTP APIs. ([source](https://stoplight.io/open-source/prism))

## Further Reading

- [Pact When to Use](https://docs.pact.io/getting_started/what_is_pact_good_for)
- [Pact JavaScript Consumer Tests](https://docs.pact.io/implementation_guides/javascript/docs/consumer)
- [Stoplight Prism](https://stoplight.io/open-source/prism)