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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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="general-purpose"
- 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 cycle"4risk: unknown5source: community6---78## Use this skill when910- Working on tdd workflows tdd cycle tasks or workflows11- Needing guidance, best practices, or checklists for tdd workflows tdd cycle1213## Do not use this skill when1415- The task is unrelated to tdd workflows tdd cycle16- You need a different domain or tool outside this scope1718## Instructions1920- Clarify goals, constraints, and required inputs.21- Apply relevant best practices and validate outcomes.22- Provide actionable steps and verification.23- If detailed examples are required, open `resources/implementation-playbook.md`.2425Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:2627[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.]2829## Configuration3031### Coverage Thresholds32- Minimum line coverage: 80%33- Minimum branch coverage: 75%34- Critical path coverage: 100%3536### Refactoring Triggers37- Cyclomatic complexity > 1038- Method length > 20 lines39- Class length > 200 lines40- Duplicate code blocks > 3 lines4142## Phase 1: Test Specification and Design4344### 1. Requirements Analysis45- Use Task tool with subagent_type="general-purpose"46- Prompt: "Analyze requirements for: $ARGUMENTS. Define acceptance criteria, identify edge cases, and create test scenarios. Output a comprehensive test specification."47- Output: Test specification, acceptance criteria, edge case matrix48- Validation: Ensure all requirements have corresponding test scenarios4950### 2. Test Architecture Design51- Use Task tool with subagent_type="general-purpose"52- Prompt: "Design test architecture for: $ARGUMENTS based on test specification. Define test structure, fixtures, mocks, and test data strategy. Ensure testability and maintainability."53- Output: Test architecture, fixture design, mock strategy54- Validation: Architecture supports isolated, fast, reliable tests5556## Phase 2: RED - Write Failing Tests5758### 3. Write Unit Tests (Failing)59- Use Task tool with subagent_type="general-purpose"60- Prompt: "Write FAILING unit tests for: $ARGUMENTS. Tests must fail initially. Include edge cases, error scenarios, and happy paths. DO NOT implement production code."61- Output: Failing unit tests, test documentation62- **CRITICAL**: Verify all tests fail with expected error messages6364### 4. Verify Test Failure65- Use Task tool with subagent_type="general-purpose"66- 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."67- Output: Test failure verification report68- **GATE**: Do not proceed until all tests fail appropriately6970## Phase 3: GREEN - Make Tests Pass7172### 5. Minimal Implementation73- Use Task tool with subagent_type="general-purpose"74- 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."75- Output: Minimal working implementation76- Constraint: No code beyond what's needed to pass tests7778### 6. Verify Test Success79- Use Task tool with subagent_type="general-purpose"80- Prompt: "Run all tests for: $ARGUMENTS and verify they pass. Check test coverage metrics. Ensure no tests were accidentally broken."81- Output: Test execution report, coverage metrics82- **GATE**: All tests must pass before proceeding8384## Phase 4: REFACTOR - Improve Code Quality8586### 7. Code Refactoring87- Use Task tool with subagent_type="general-purpose"88- Prompt: "Refactor implementation for: $ARGUMENTS while keeping tests green. Apply SOLID principles, remove duplication, improve naming, and optimize performance. Run tests after each refactoring."89- Output: Refactored code, refactoring report90- Constraint: Tests must remain green throughout9192### 8. Test Refactoring93- Use Task tool with subagent_type="general-purpose"94- Prompt: "Refactor tests for: $ARGUMENTS. Remove test duplication, improve test names, extract common fixtures, and enhance test readability. Ensure tests still provide same coverage."95- Output: Refactored tests, improved test structure96- Validation: Coverage metrics unchanged or improved9798## Phase 5: Integration and System Tests99100### 9. Write Integration Tests (Failing First)101- Use Task tool with subagent_type="general-purpose"102- Prompt: "Write FAILING integration tests for: $ARGUMENTS. Test component interactions, API contracts, and data flow. Tests must fail initially."103- Output: Failing integration tests104- Validation: Tests fail due to missing integration logic105106### 10. Implement Integration107- Use Task tool with subagent_type="general-purpose"108- Prompt: "Implement integration code for: $ARGUMENTS to make integration tests pass. Focus on component interaction and data flow."109- Output: Integration implementation110- Validation: All integration tests pass111112## Phase 6: Continuous Improvement Cycle113114### 11. Performance and Edge Case Tests115- Use Task tool with subagent_type="general-purpose"116- Prompt: "Add performance tests and additional edge case tests for: $ARGUMENTS. Include stress tests, boundary tests, and error recovery tests."117- Output: Extended test suite118- Metric: Increased test coverage and scenario coverage119120### 12. Final Code Review121- Use Task tool with subagent_type="general-purpose"122- Prompt: "Perform comprehensive review of: $ARGUMENTS. Verify TDD process was followed, check code quality, test quality, and coverage. Suggest improvements."123- Output: Review report, improvement suggestions124- Action: Implement critical suggestions while maintaining green tests125126## Incremental Development Mode127128For test-by-test development:1291. Write ONE failing test1302. Make ONLY that test pass1313. Refactor if needed1324. Repeat for next test133134Use this approach by adding `--incremental` flag to focus on one test at a time.135136## Test Suite Mode137138For comprehensive test suite development:1391. Write ALL tests for a feature/module (failing)1402. Implement code to pass ALL tests1413. Refactor entire module1424. Add integration tests143144Use this approach by adding `--suite` flag for batch test development.145146## Validation Checkpoints147148### RED Phase Validation149- [ ] All tests written before implementation150- [ ] All tests fail with meaningful error messages151- [ ] Test failures are due to missing implementation152- [ ] No test passes accidentally153154### GREEN Phase Validation155- [ ] All tests pass156- [ ] No extra code beyond test requirements157- [ ] Coverage meets minimum thresholds158- [ ] No test was modified to make it pass159160### REFACTOR Phase Validation161- [ ] All tests still pass after refactoring162- [ ] Code complexity reduced163- [ ] Duplication eliminated164- [ ] Performance improved or maintained165- [ ] Test readability improved166167## Coverage Reports168169Generate coverage reports after each phase:170- Line coverage171- Branch coverage172- Function coverage173- Statement coverage174175## Failure Recovery176177If TDD discipline is broken:1781. **STOP** immediately1792. Identify which phase was violated1803. Rollback to last valid state1814. Resume from correct phase1825. Document lesson learned183184## TDD Metrics Tracking185186Track and report:187- Time in each phase (Red/Green/Refactor)188- Number of test-implementation cycles189- Coverage progression190- Refactoring frequency191- Defect escape rate192193## Anti-Patterns to Avoid194195- Writing implementation before tests196- Writing tests that already pass197- Skipping the refactor phase198- Writing multiple features without tests199- Modifying tests to make them pass200- Ignoring failing tests201- Writing tests after implementation202203## Success Criteria204205- 100% of code written test-first206- All tests pass continuously207- Coverage exceeds thresholds208- Code complexity within limits209- Zero defects in covered code210- Clear test documentation211- Fast test execution (< 5 seconds for unit tests)212213## Notes214215- Enforce strict RED-GREEN-REFACTOR discipline216- Each phase must be completed before moving to next217- Tests are the specification218- If a test is hard to write, the design needs improvement219- Refactoring is NOT optional220- Keep test execution fast221- Tests should be independent and isolated222223TDD implementation for: $ARGUMENTS