| name | contract-testing |
| description | Consumer-driven contract testing with Pact, schema validation, and API compatibility verification. |
| layer | domain |
| category | testing |
| triggers | ["contract test","pact","consumer driven","api contract","schema validation"] |
| inputs | ["API contract testing requirements","Consumer-driven testing setup","Schema validation strategies","API compatibility verification"] |
| outputs | ["Pact consumer and provider tests","Schema validation configurations","Contract verification workflows","CI/CD integration for contract tests"] |
| linksTo | ["api-testing","testing-patterns","openapi","microservices"] |
| linkedFrom | [] |
| preferredNextSkills | ["api-testing","testing-patterns","microservices"] |
| fallbackSkills | ["openapi"] |
| riskLevel | low |
| memoryReadPolicy | selective |
| memoryWritePolicy | none |
| sideEffects | [] |
Consumer-Driven Contract Testing
Purpose
Provide expert guidance on consumer-driven contract testing (CDCT) with Pact, schema validation with Zod/JSON Schema, API compatibility verification, and CI integration. Ensures APIs evolve without breaking consumers in microservice architectures.
Why Contract Testing
┌────────────────────────────────────────────────┐
│ Testing Pyramid for APIs │
│ │
│ ┌──────────┐ │
│ │ E2E │ Slow, brittle │
│ ┌─┴──────────┴─┐ │
│ │ Integration │ Needs live deps │
│ ┌─┴──────────────┴─┐ │
│ │ Contract Tests │ Fast, isolated │ ← This skill
│ ┌─┴──────────────────┴─┐ │
│ │ Unit Tests │ │
│ └───────────────────────┘ │
└────────────────────────────────────────────────┘
Contract tests verify that a provider API meets the expectations of its consumers without requiring both services to be running simultaneously.
Pact Consumer Test (TypeScript)
The consumer defines what it expects from the provider:
import { PactV4, MatchersV3 } from '@pact-foundation/pact';
import { UserApiClient } from '../src/user-api-client';
const { like, eachLike, string, integer, datetime } = MatchersV3;
const provider = new PactV4({
consumer: 'OrderService',
provider: 'UserService',
dir: './pacts',
});
describe('User Service API', () => {
(, {
(, () => {
provider
.()
.()
.()
.(, , {
builder.({ : });
})
.(, {
builder
.({ : })
.({
: (),
: (),
: (),
: (, ),
: ({
: (),
: (),
}),
});
})
.( (mockServer) => {
client = (mockServer.);
user = client.();
(user.).();
(user.).();
(user.).();
});
});
(, () => {
provider
.()
.()
.()
.(, )
.(, {
builder.({
: (),
: (),
});
})
.( (mockServer) => {
client = (mockServer.);
(client.())..();
});
});
});
(, {
(, () => {
provider
.()
.()
.(, , {
builder
.({ : })
.({
: ,
: ,
});
})
.(, {
builder.({
: (),
: (),
: (),
});
})
.( (mockServer) => {
client = (mockServer.);
user = client.({
: ,
: ,
});
(user.).();
});
});
});
});