Contract testing verify API contract (format, structure, behavior) giữa service provider và consumer mà không cần cả hai chạy đồng thời — critical trong microservices.
- Consumer-driven contract testing với Pact: Consumer viết tests định nghĩa expectations về provider responses (pact file); Provider chạy pact file để verify nó thỏa mãn consumer expectations.
- Pact Broker: central repository cho pact files, track which consumer versions are compatible với which provider versions.
- Can-I-Deploy tool: query Pact Broker để check nếu service version có thể deploy safely — 'can consumer v2 deploy if provider is v3?'.
- Tại sao quan trọng hơn E2E tests trong microservices: E2E tests cần tất cả services chạy đồng thời (expensive, slow, flaky); contract tests chạy independently per service — fast, reliable, pinpoint exactly which service broke contract.
- Breaking change detection: nếu provider thay đổi response schema, pact verification fail ngay trong CI trước khi deploy — không phải phát hiện trong production.
- Schema registry (Avro, Protobuf) cho event-driven architecture: schema evolution rules, backward/forward compatibility checks — contract testing cho async messaging.
- OpenAPI contract testing: Dredd, Spectral verify API implementation against OpenAPI spec — simpler than Pact nhưng ít powerful.