Red-Green-Refactor cycle with Amazon's test pyramid (80% unit, 15% integration, 5% e2e). Coverage gates, DAMP over DRY in tests, canary tests in production.
Instalação
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Red-Green-Refactor cycle with Amazon's test pyramid (80% unit, 15% integration, 5% e2e). Coverage gates, DAMP over DRY in tests, canary tests in production.
leadership_principles
["Insist on the Highest Standards","Ownership","Dive Deep"]
Overview
Test-Driven Development (TDD) at Amazon means writing the test before the implementation—always. The Red-Green-Refactor cycle is not a suggestion; it is the mechanism that ensures code correctness, enables fearless refactoring, and keeps deployment pipelines green.
Amazon's test philosophy follows the test pyramid: a broad base of fast unit tests (80%), a middle layer of integration tests (15%), and a thin cap of end-to-end tests (5%). This ratio exists because unit tests are fast, deterministic, and cheap to maintain. Integration tests verify contracts between components. End-to-end tests validate customer-visible behavior but are slow and brittle.
Beyond pre-deployment testing, Amazon runs canary tests in production—synthetic requests that continuously verify real system behavior. When canaries fail, alarms fire before customers notice.
When to Use
Before writing any production code (the "Red" step comes first)
When fixing a bug (write the failing test that reproduces it first)
When refactoring existing code (ensure tests exist before changing behavior)
During code review (verify test coverage for every behavior change)
When setting up deployment pipelines (configure coverage gates)
When onboarding a new service (establish canary tests immediately)
Amazon Context
At Amazon, untested code does not ship. Pipelines enforce minimum coverage thresholds (typically 80% line coverage, 90% branch coverage for critical paths). Code review explicitly evaluates test quality—a change without tests is rejected regardless of how correct the implementation appears.
The CI/CD toolchain (build system, deployment pipelines, code analysis) integrates testing at every stage: pre-commit hooks run unit tests locally, CI runs the full suite, and post-deployment canaries verify production health. Teams own their test infrastructure the same way they own their production infrastructure.
Amazon's testing culture learned from expensive failures: services that shipped with "we'll add tests later" invariably accumulated tech debt that made changes risky, deployments scary, and on-call rotations miserable. TDD inverts this—tests are the first thing you build, not the last.
The Process
1. Red-Green-Refactor Cycle
┌─────────────────────────────────────────┐
│ RED: Write a failing test │
│ ↓ │
│ GREEN: Write minimum code to pass │
│ ↓ │
│ REFACTOR: Clean up, tests still pass │
│ ↓ │
│ Repeat │
└─────────────────────────────────────────┘
Red Phase:
Write one test that describes desired behavior
Run it. It must fail. If it passes, your test is wrong.
The test name describes the behavior: test_order_rejected_when_inventory_zero
Green Phase:
Write the minimum code to make the test pass
No premature abstraction. No "while I'm here" changes.
Hardcode values if that's all the test requires—the next test will force generalization.