マイクロサービスと分散システムのテストはモノリスのテストよりも複雑です。サービスはネットワーク上で相互作用し、独立したデプロイメントと分散的な障害モードを持ちます。コントラクトテスト、サービスレベルのテスト、慎重な統合/E2Eアプローチなどの戦略が必要です。
課題
Distributed systems are harder to test than monoliths:
→ many SERVICES interacting over the NETWORK (latency, failures, partial outages)
→ services deployed INDEPENDENTLY → integration/compatibility concerns
→ E2E testing across many services is SLOW, BRITTLE, and complex to set up
→ distributed failure modes (a service down, slow, returning errors)
テスト戦略
✓ Test each service in ISOLATION (its own unit + integration tests) — the foundation
✓ CONTRACT TESTING (e.g. Pact) → verify services agree on their API CONTRACTS without
full integration → catches breaking changes between services (provider/consumer) →
a KEY technique for microservices (avoids brittle full E2E for compatibility)
✓ Component/service-level tests → test a service with its dependencies MOCKED/stubbed
✓ LIMITED E2E → a few critical cross-service flows (not exhaustive — too brittle/slow)
✓ Test RESILIENCE → how services handle dependency failures (timeouts, retries,
circuit breakers); CHAOS testing for failure modes
