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