Implementing Testing Patterns
1. Consumer-Driven Contract Testing Pattern
| Aspect | Detail |
|---|---|
| Mechanism | Consumer defines expected interactions; provider verified against contract |
| Benefit | Catch breaking changes before integration |
| Tools | Pact, Spring Cloud Contract |
| Workflow | Consumer publishes contract → broker → provider verifies |
2. Service Component Test Pattern
| Aspect | Detail |
|---|---|
| Scope | One service in isolation; in-process or process-level |
| External Deps | Test doubles or testcontainers |
| Tools | Spring Boot Test, Testcontainers, WireMock |
| Benefit | Fast; reliable; tests real service stack minus network deps |
3. Integration Contract Test Pattern
| Aspect | Detail |
|---|---|
| Verifies | Service correctly integrates with real external (DB, broker) |
| Differs From | Component test (mocks); E2E test (full stack) |
| Tools | Testcontainers (real Postgres, Kafka in CI) |
4. End-to-End Test Pattern
| Aspect | Detail |
|---|---|
| Scope | Full system through real UI / API |
| Pros | Catches integration issues humans care about |
| Cons | Slow, brittle, expensive |
| Strategy | Few critical-path tests only ("test pyramid") |
| Tools | Playwright, Cypress, Selenium |
5. Service Virtualization Pattern
| Aspect | Detail |
|---|---|
| Mechanism | Simulate dependent services with realistic responses (incl latency, errors) |
| Use | Test against unavailable / costly / 3rd-party services |
| Tools | WireMock, Hoverfly, Mountebank, Microcks |
6. Test Double Pattern
| Type | Use |
|---|---|
| Dummy | Filler arg; never used |
| Stub | Returns canned answers |
| Spy | Stub + records calls |
| Mock | Pre-programmed expectations; verifies interactions |
| Fake | Working impl with shortcut (in-memory DB) |
7. Chaos Engineering Pattern
| Principle | Detail |
|---|---|
| Hypothesize | "System tolerates loss of 1 AZ" |
| Inject | Failure (kill pod, latency, packet loss) |
| Observe | Verify SLOs hold |
| Blast Radius | Start small (staging) → expand (production with kill switch) |
| Tools | Chaos Mesh, LitmusChaos, Gremlin, AWS FIS |
8. Canary Testing Pattern
| Aspect | Detail |
|---|---|
| Mechanism | Run automated tests against canary deploy before promotion |
| Tests | Smoke, key journey, perf check |
| Result | Auto-promote on pass; rollback on fail |
9. Shadow Testing Pattern
| Aspect | Detail |
|---|---|
| Mechanism | Mirror prod traffic to candidate; compare outputs |
| Use | Validate refactor / rewrite under real load |
| Cautions | Read-only or idempotent only; isolate side-effects |
| Tools | Diffy (Twitter), GitHub Scientist, Envoy mirroring |
10. Synthetic Transaction Pattern
| Aspect | Detail |
|---|---|
| Definition | Scripted business transaction run continuously in prod |
| Use | Detect outage / regression before real users do |
| Examples | Test login + add to cart + checkout (use marker user) |
| Cautions | Mark synthetic data; exclude from analytics & billing |