API Contract Testing

API Contract Testing

Guides an AI agent to write API contract tests with Pact, OpenAPI and JSON schema validation so service changes do not break consumers.

Skill files9 files

references/

scripts/

templates/

SKILL.md103 lines
1
---
2
name: api-contract-testing
3
description: >
4
Verify API contracts between services to ensure compatibility and prevent
5
breaking changes. Use for contract testing, Pact, API contract validation,
6
schema validation, and consumer-driven contracts.
7
---
8
9
# API Contract Testing
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Contract testing verifies that APIs honor their contracts between consumers and providers. It ensures that service changes don't break dependent consumers without requiring full integration tests. Contract tests validate request/response formats, data types, and API behavior independently.
22
23
## When to Use
24
25
- Testing microservices communication
26
- Preventing breaking API changes
27
- Validating API versioning
28
- Testing consumer-provider contracts
29
- Ensuring backward compatibility
30
- Validating OpenAPI/Swagger specifications
31
- Testing third-party API integrations
32
- Catching contract violations in CI
33
34
## Quick Start
35
36
Minimal working example:
37
38
```typescript
39
// tests/pact/user-service.pact.test.ts
40
import { PactV3, MatchersV3 } from "@pact-foundation/pact";
41
import { UserService } from "../../src/services/UserService";
42
43
const { like, eachLike, iso8601DateTimeWithMillis } = MatchersV3;
44
45
const provider = new PactV3({
46
consumer: "OrderService",
47
provider: "UserService",
48
port: 1234,
49
dir: "./pacts",
50
});
51
52
describe("User Service Contract", () => {
53
const userService = new UserService("http://localhost:1234");
54
55
describe("GET /users/:id", () => {
56
test("returns user when found", async () => {
57
await provider
58
.given("user with ID 123 exists")
59
.uponReceiving("a request for user 123")
60
.withRequest({
61
method: "GET",
62
path: "/users/123",
63
headers: {
64
// ... (see reference guides for full implementation)
65
```
66
67
## Reference Guides
68
69
Detailed implementations in the `references/` directory:
70
71
| Guide | Contents |
72
|---|---|
73
| [Pact for Consumer-Driven Contracts](references/pact-for-consumer-driven-contracts.md) | Pact for Consumer-Driven Contracts |
74
| [OpenAPI Schema Validation](references/openapi-schema-validation.md) | OpenAPI Schema Validation |
75
| [JSON Schema Validation](references/json-schema-validation.md) | JSON Schema Validation |
76
| [REST Assured for Java](references/rest-assured-for-java.md) | REST Assured for Java |
77
| [Contract Testing with Postman](references/contract-testing-with-postman.md) | Contract Testing with Postman |
78
| [Pact Broker Integration](references/pact-broker-integration.md) | Pact Broker Integration |
79
80
## Best Practices
81
82
### ✅ DO
83
84
- Test contracts from consumer perspective
85
- Use matchers for flexible matching
86
- Validate schema structure, not specific values
87
- Version your contracts
88
- Test error responses
89
- Use Pact broker for contract sharing
90
- Run contract tests in CI
91
- Test backward compatibility
92
93
### ❌ DON'T
94
95
- Test business logic in contract tests
96
- Hard-code specific values in contracts
97
- Skip error scenarios
98
- Test UI in contract tests
99
- Ignore contract versioning
100
- Deploy without contract verification
101
- Test implementation details
102
- Mock contract tests
103

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…