Use this skill when
- Working on tdd workflows tdd cycle tasks or workflows
- Needing guidance, best practices, or checklists for tdd workflows tdd cycle
Do not use this skill when
- The task is unrelated to tdd workflows tdd cycle
- You need a different domain or tool outside this scope
Instructions
- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.
- If detailed examples are required, open
resources/implementation-playbook.md.
Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:
[Extended thinking: This workflow enforces test-first development through coordinated agent orchestration. Each phase of the TDD cycle is strictly enforced with fail-first verification, incremental implementation, and continuous refactoring. The workflow supports both single test and test suite approaches with configurable coverage thresholds.]
Configuration
Coverage Thresholds
- Minimum line coverage: 80%
- Minimum branch coverage: 75%
- Critical path coverage: 100%
Refactoring Triggers
- Cyclomatic complexity > 10
- Method length > 20 lines
- Class length > 200 lines
- Duplicate code blocks > 3 lines
Phase 1: Test Specification and Design
1. Requirements Analysis
- Use Task tool with subagent_type="comprehensive-review::architect-review"
- Prompt: "Analyze requirements for: $ARGUMENTS. Define acceptance criteria, identify edge cases, and create test scenarios. Output a comprehensive test specification."
- Output: Test specification, acceptance criteria, edge case matrix
- Validation: Ensure all requirements have corresponding test scenarios
2. Test Architecture Design
- Use Task tool with subagent_type="unit-testing::test-automator"
- Prompt: "Design test architecture for: $ARGUMENTS based on test specification. Define test structure, fixtures, mocks, and test data strategy. Ensure testability and maintainability."
- Output: Test architecture, fixture design, mock strategy
- Validation: Architecture supports isolated, fast, reliable tests
Phase 2: RED - Write Failing Tests
3. Write Unit Tests (Failing)
- Use Task tool with subagent_type="unit-testing::test-automator"
- Prompt: "Write FAILING unit tests for: $ARGUMENTS. Tests must fail initially. Include edge cases, error scenarios, and happy paths. DO NOT implement production code."
- Output: Failing unit tests, test documentation
- CRITICAL: Verify all tests fail with expected error messages
4. Verify Test Failure
- Use Task tool with subagent_type="tdd-workflows::code-reviewer"
- Prompt: "Verify that all tests for: $ARGUMENTS are failing correctly. Ensure failures are for the right reasons (missing implementation, not test errors). Confirm no false positives."
- Output: Test failure verification report
- GATE: Do not proceed until all tests fail appropriately
Phase 3: GREEN - Make Tests Pass
5. Minimal Implementation
- Use Task tool with subagent_type="backend-development::backend-architect"
- Prompt: "Implement MINIMAL code to make tests pass for: $ARGUMENTS. Focus only on making tests green. Do not add extra features or optimizations. Keep it simple."
- Output: Minimal working implementation
- Constraint: No code beyond what's needed to pass tests
6. Verify Test Success
- Use Task tool with subagent_type="unit-testing::test-automator"
- Prompt: "Run all tests for: $ARGUMENTS and verify they pass. Check test coverage metrics. Ensure no tests were accidentally broken."
- Output: Test execution report, coverage metrics
- GATE: All tests must pass before proceeding
Phase 4: REFACTOR - Improve Code Quality
7. Code Refactoring
- Use Task tool with subagent_type="tdd-workflows::code-reviewer"
- Prompt: "Refactor implementation for: $ARGUMENTS while keeping tests green. Apply SOLID principles, remove duplication, improve naming, and optimize performance. Run tests after each refactoring."
- Output: Refactored code, refactoring report
- Constraint: Tests must remain green throughout
8. Test Refactoring
- Use Task tool with subagent_type="unit-testing::test-automator"
- Prompt: "Refactor tests for: $ARGUMENTS. Remove test duplication, improve test names, extract common fixtures, and enhance test readability. Ensure tests still provide same coverage."
- Output: Refactored tests, improved test structure
- Validation: Coverage metrics unchanged or improved
Phase 5: Integration and System Tests
9. Write Integration Tests (Failing First)
- Use Task tool with subagent_type="unit-testing::test-automator"
- Prompt: "Write FAILING integration tests for: $ARGUMENTS. Test component interactions, API contracts, and data flow. Tests must fail initially."
- Output: Failing integration tests
- Validation: Tests fail due to missing integration logic
10. Implement Integration
- Use Task tool with subagent_type="backend-development::backend-architect"
- Prompt: "Implement integration code for: $ARGUMENTS to make integration tests pass. Focus on component interaction and data flow."
- Output: Integration implementation
- Validation: All integration tests pass
Phase 6: Continuous Improvement Cycle
11. Performance and Edge Case Tests
- Use Task tool with subagent_type="unit-testing::test-automator"
- Prompt: "Add performance tests and additional edge case tests for: $ARGUMENTS. Include stress tests, boundary tests, and error recovery tests."
- Output: Extended test suite
- Metric: Increased test coverage and scenario coverage
12. Final Code Review
- Use Task tool with subagent_type="comprehensive-review::architect-review"
- Prompt: "Perform comprehensive review of: $ARGUMENTS. Verify TDD process was followed, check code quality, test quality, and coverage. Suggest improvements."
- Output: Review report, improvement suggestions
- Action: Implement critical suggestions while maintaining green tests
Incremental Development Mode
For test-by-test development:
- Write ONE failing test
- Make ONLY that test pass
- Refactor if needed
- Repeat for next test
Use this approach by adding --incremental flag to focus on one test at a time.
Test Suite Mode
For comprehensive test suite development:
- Write ALL tests for a feature/module (failing)
- Implement code to pass ALL tests
- Refactor entire module
- Add integration tests
Use this approach by adding --suite flag for batch test development.
Validation Checkpoints
RED Phase Validation
GREEN Phase Validation
REFACTOR Phase Validation
Coverage Reports
Generate coverage reports after each phase:
- Line coverage
- Branch coverage
- Function coverage
- Statement coverage
Failure Recovery
If TDD discipline is broken:
- STOP immediately
- Identify which phase was violated
- Rollback to last valid state
- Resume from correct phase
- Document lesson learned
TDD Metrics Tracking
Track and report:
- Time in each phase (Red/Green/Refactor)
- Number of test-implementation cycles
- Coverage progression
- Refactoring frequency
- Defect escape rate
Anti-Patterns to Avoid
- Writing implementation before tests
- Writing tests that already pass
- Skipping the refactor phase
- Writing multiple features without tests
- Modifying tests to make them pass
- Ignoring failing tests
- Writing tests after implementation
Success Criteria
- 100% of code written test-first
- All tests pass continuously
- Coverage exceeds thresholds
- Code complexity within limits
- Zero defects in covered code
- Clear test documentation
- Fast test execution (< 5 seconds for unit tests)
Notes
- Enforce strict RED-GREEN-REFACTOR discipline
- Each phase must be completed before moving to next
- Tests are the specification
- If a test is hard to write, the design needs improvement
- Refactoring is NOT optional
- Keep test execution fast
- Tests should be independent and isolated
TDD implementation for: $ARGUMENTS
1---2name: tdd-workflows-tdd-cycle3description: Use when working with tdd workflows tdd cycle4---5
6## Use this skill when
7
8- Working on tdd workflows tdd cycle tasks or workflows
9- Needing guidance, best practices, or checklists for tdd workflows tdd cycle
10
11## Do not use this skill when
12
13- The task is unrelated to tdd workflows tdd cycle
14- You need a different domain or tool outside this scope
15
16## Instructions
17
18- Clarify goals, constraints, and required inputs.
19- Apply relevant best practices and validate outcomes.
20- Provide actionable steps and verification.
21- If detailed examples are required, open `resources/implementation-playbook.md`.
22
23Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:
24
25[Extended thinking: This workflow enforces test-first development through coordinated agent orchestration. Each phase of the TDD cycle is strictly enforced with fail-first verification, incremental implementation, and continuous refactoring. The workflow supports both single test and test suite approaches with configurable coverage thresholds.]
26
27## Configuration
28
29### Coverage Thresholds
30- Minimum line coverage: 80%
31- Minimum branch coverage: 75%
32- Critical path coverage: 100%
33
34### Refactoring Triggers
35- Cyclomatic complexity > 10
36- Method length > 20 lines
37- Class length > 200 lines
38- Duplicate code blocks > 3 lines
39
40## Phase 1: Test Specification and Design
41
42### 1. Requirements Analysis
43- Use Task tool with subagent_type="comprehensive-review::architect-review"
44- Prompt: "Analyze requirements for: $ARGUMENTS. Define acceptance criteria, identify edge cases, and create test scenarios. Output a comprehensive test specification."
45- Output: Test specification, acceptance criteria, edge case matrix
46- Validation: Ensure all requirements have corresponding test scenarios
47
48### 2. Test Architecture Design
49- Use Task tool with subagent_type="unit-testing::test-automator"
50- Prompt: "Design test architecture for: $ARGUMENTS based on test specification. Define test structure, fixtures, mocks, and test data strategy. Ensure testability and maintainability."
51- Output: Test architecture, fixture design, mock strategy
52- Validation: Architecture supports isolated, fast, reliable tests
53
54## Phase 2: RED - Write Failing Tests
55
56### 3. Write Unit Tests (Failing)
57- Use Task tool with subagent_type="unit-testing::test-automator"
58- Prompt: "Write FAILING unit tests for: $ARGUMENTS. Tests must fail initially. Include edge cases, error scenarios, and happy paths. DO NOT implement production code."
59- Output: Failing unit tests, test documentation
60- **CRITICAL**: Verify all tests fail with expected error messages
61
62### 4. Verify Test Failure
63- Use Task tool with subagent_type="tdd-workflows::code-reviewer"
64- Prompt: "Verify that all tests for: $ARGUMENTS are failing correctly. Ensure failures are for the right reasons (missing implementation, not test errors). Confirm no false positives."
65- Output: Test failure verification report
66- **GATE**: Do not proceed until all tests fail appropriately
67
68## Phase 3: GREEN - Make Tests Pass
69
70### 5. Minimal Implementation
71- Use Task tool with subagent_type="backend-development::backend-architect"
72- Prompt: "Implement MINIMAL code to make tests pass for: $ARGUMENTS. Focus only on making tests green. Do not add extra features or optimizations. Keep it simple."
73- Output: Minimal working implementation
74- Constraint: No code beyond what's needed to pass tests
75
76### 6. Verify Test Success
77- Use Task tool with subagent_type="unit-testing::test-automator"
78- Prompt: "Run all tests for: $ARGUMENTS and verify they pass. Check test coverage metrics. Ensure no tests were accidentally broken."
79- Output: Test execution report, coverage metrics
80- **GATE**: All tests must pass before proceeding
81
82## Phase 4: REFACTOR - Improve Code Quality
83
84### 7. Code Refactoring
85- Use Task tool with subagent_type="tdd-workflows::code-reviewer"
86- Prompt: "Refactor implementation for: $ARGUMENTS while keeping tests green. Apply SOLID principles, remove duplication, improve naming, and optimize performance. Run tests after each refactoring."
87- Output: Refactored code, refactoring report
88- Constraint: Tests must remain green throughout
89
90### 8. Test Refactoring
91- Use Task tool with subagent_type="unit-testing::test-automator"
92- Prompt: "Refactor tests for: $ARGUMENTS. Remove test duplication, improve test names, extract common fixtures, and enhance test readability. Ensure tests still provide same coverage."
93- Output: Refactored tests, improved test structure
94- Validation: Coverage metrics unchanged or improved
95
96## Phase 5: Integration and System Tests
97
98### 9. Write Integration Tests (Failing First)
99- Use Task tool with subagent_type="unit-testing::test-automator"
100- Prompt: "Write FAILING integration tests for: $ARGUMENTS. Test component interactions, API contracts, and data flow. Tests must fail initially."
101- Output: Failing integration tests
102- Validation: Tests fail due to missing integration logic
103
104### 10. Implement Integration
105- Use Task tool with subagent_type="backend-development::backend-architect"
106- Prompt: "Implement integration code for: $ARGUMENTS to make integration tests pass. Focus on component interaction and data flow."
107- Output: Integration implementation
108- Validation: All integration tests pass
109
110## Phase 6: Continuous Improvement Cycle
111
112### 11. Performance and Edge Case Tests
113- Use Task tool with subagent_type="unit-testing::test-automator"
114- Prompt: "Add performance tests and additional edge case tests for: $ARGUMENTS. Include stress tests, boundary tests, and error recovery tests."
115- Output: Extended test suite
116- Metric: Increased test coverage and scenario coverage
117
118### 12. Final Code Review
119- Use Task tool with subagent_type="comprehensive-review::architect-review"
120- Prompt: "Perform comprehensive review of: $ARGUMENTS. Verify TDD process was followed, check code quality, test quality, and coverage. Suggest improvements."
121- Output: Review report, improvement suggestions
122- Action: Implement critical suggestions while maintaining green tests
123
124## Incremental Development Mode
125
126For test-by-test development:
1271. Write ONE failing test
1282. Make ONLY that test pass
1293. Refactor if needed
1304. Repeat for next test
131
132Use this approach by adding `--incremental` flag to focus on one test at a time.
133
134## Test Suite Mode
135
136For comprehensive test suite development:
1371. Write ALL tests for a feature/module (failing)
1382. Implement code to pass ALL tests
1393. Refactor entire module
1404. Add integration tests
141
142Use this approach by adding `--suite` flag for batch test development.
143
144## Validation Checkpoints
145
146### RED Phase Validation
147- [ ] All tests written before implementation
148- [ ] All tests fail with meaningful error messages
149- [ ] Test failures are due to missing implementation
150- [ ] No test passes accidentally
151
152### GREEN Phase Validation
153- [ ] All tests pass
154- [ ] No extra code beyond test requirements
155- [ ] Coverage meets minimum thresholds
156- [ ] No test was modified to make it pass
157
158### REFACTOR Phase Validation
159- [ ] All tests still pass after refactoring
160- [ ] Code complexity reduced
161- [ ] Duplication eliminated
162- [ ] Performance improved or maintained
163- [ ] Test readability improved
164
165## Coverage Reports
166
167Generate coverage reports after each phase:
168- Line coverage
169- Branch coverage
170- Function coverage
171- Statement coverage
172
173## Failure Recovery
174
175If TDD discipline is broken:
1761. **STOP** immediately
1772. Identify which phase was violated
1783. Rollback to last valid state
1794. Resume from correct phase
1805. Document lesson learned
181
182## TDD Metrics Tracking
183
184Track and report:
185- Time in each phase (Red/Green/Refactor)
186- Number of test-implementation cycles
187- Coverage progression
188- Refactoring frequency
189- Defect escape rate
190
191## Anti-Patterns to Avoid
192
193- Writing implementation before tests
194- Writing tests that already pass
195- Skipping the refactor phase
196- Writing multiple features without tests
197- Modifying tests to make them pass
198- Ignoring failing tests
199- Writing tests after implementation
200
201## Success Criteria
202
203- 100% of code written test-first
204- All tests pass continuously
205- Coverage exceeds thresholds
206- Code complexity within limits
207- Zero defects in covered code
208- Clear test documentation
209- Fast test execution (< 5 seconds for unit tests)
210
211## Notes
212
213- Enforce strict RED-GREEN-REFACTOR discipline
214- Each phase must be completed before moving to next
215- Tests are the specification
216- If a test is hard to write, the design needs improvement
217- Refactoring is NOT optional
218- Keep test execution fast
219- Tests should be independent and isolated
220
221TDD implementation for: $ARGUMENTS