$npx -y skills add One-Man-Company/Skills-ContextManager --skill tdd-workflowTest-Driven Development workflow principles. RED-GREEN-REFACTOR cycle.
| 1 | # TDD Workflow |
| 2 | |
| 3 | > Write tests first, code second. |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## 1. The TDD Cycle |
| 8 | |
| 9 | ``` |
| 10 | 🔴 RED → Write failing test |
| 11 | ↓ |
| 12 | 🟢 GREEN → Write minimal code to pass |
| 13 | ↓ |
| 14 | 🔵 REFACTOR → Improve code quality |
| 15 | ↓ |
| 16 | Repeat... |
| 17 | ``` |
| 18 | |
| 19 | --- |
| 20 | |
| 21 | ## 2. The Three Laws of TDD |
| 22 | |
| 23 | 1. Write production code only to make a failing test pass |
| 24 | 2. Write only enough test to demonstrate failure |
| 25 | 3. Write only enough code to make the test pass |
| 26 | |
| 27 | --- |
| 28 | |
| 29 | ## 3. RED Phase Principles |
| 30 | |
| 31 | ### What to Write |
| 32 | |
| 33 | | Focus | Example | |
| 34 | |-------|---------| |
| 35 | | Behavior | "should add two numbers" | |
| 36 | | Edge cases | "should handle empty input" | |
| 37 | | Error states | "should throw for invalid data" | |
| 38 | |
| 39 | ### RED Phase Rules |
| 40 | |
| 41 | - Test must fail first |
| 42 | - Test name describes expected behavior |
| 43 | - One assertion per test (ideally) |
| 44 | |
| 45 | --- |
| 46 | |
| 47 | ## 4. GREEN Phase Principles |
| 48 | |
| 49 | ### Minimum Code |
| 50 | |
| 51 | | Principle | Meaning | |
| 52 | |-----------|---------| |
| 53 | | **YAGNI** | You Aren't Gonna Need It | |
| 54 | | **Simplest thing** | Write the minimum to pass | |
| 55 | | **No optimization** | Just make it work | |
| 56 | |
| 57 | ### GREEN Phase Rules |
| 58 | |
| 59 | - Don't write unneeded code |
| 60 | - Don't optimize yet |
| 61 | - Pass the test, nothing more |
| 62 | |
| 63 | --- |
| 64 | |
| 65 | ## 5. REFACTOR Phase Principles |
| 66 | |
| 67 | ### What to Improve |
| 68 | |
| 69 | | Area | Action | |
| 70 | |------|--------| |
| 71 | | Duplication | Extract common code | |
| 72 | | Naming | Make intent clear | |
| 73 | | Structure | Improve organization | |
| 74 | | Complexity | Simplify logic | |
| 75 | |
| 76 | ### REFACTOR Rules |
| 77 | |
| 78 | - All tests must stay green |
| 79 | - Small incremental changes |
| 80 | - Commit after each refactor |
| 81 | |
| 82 | --- |
| 83 | |
| 84 | ## 6. AAA Pattern |
| 85 | |
| 86 | Every test follows: |
| 87 | |
| 88 | | Step | Purpose | |
| 89 | |------|---------| |
| 90 | | **Arrange** | Set up test data | |
| 91 | | **Act** | Execute code under test | |
| 92 | | **Assert** | Verify expected outcome | |
| 93 | |
| 94 | --- |
| 95 | |
| 96 | ## 7. When to Use TDD |
| 97 | |
| 98 | | Scenario | TDD Value | |
| 99 | |----------|-----------| |
| 100 | | New feature | High | |
| 101 | | Bug fix | High (write test first) | |
| 102 | | Complex logic | High | |
| 103 | | Exploratory | Low (spike, then TDD) | |
| 104 | | UI layout | Low | |
| 105 | |
| 106 | --- |
| 107 | |
| 108 | ## 8. Test Prioritization |
| 109 | |
| 110 | | Priority | Test Type | |
| 111 | |----------|-----------| |
| 112 | | 1 | Happy path | |
| 113 | | 2 | Error cases | |
| 114 | | 3 | Edge cases | |
| 115 | | 4 | Performance | |
| 116 | |
| 117 | --- |
| 118 | |
| 119 | ## 9. Anti-Patterns |
| 120 | |
| 121 | | ❌ Don't | ✅ Do | |
| 122 | |----------|-------| |
| 123 | | Skip the RED phase | Watch test fail first | |
| 124 | | Write tests after | Write tests before | |
| 125 | | Over-engineer initial | Keep it simple | |
| 126 | | Multiple asserts | One behavior per test | |
| 127 | | Test implementation | Test behavior | |
| 128 | |
| 129 | --- |
| 130 | |
| 131 | ## 10. AI-Augmented TDD |
| 132 | |
| 133 | ### Multi-Agent Pattern |
| 134 | |
| 135 | | Agent | Role | |
| 136 | |-------|------| |
| 137 | | Agent A | Write failing tests (RED) | |
| 138 | | Agent B | Implement to pass (GREEN) | |
| 139 | | Agent C | Optimize (REFACTOR) | |
| 140 | |
| 141 | --- |
| 142 | |
| 143 | > **Remember:** The test is the specification. If you can't write a test, you don't understand the requirement. |