Selective Reading Rule
Start with:
references/senior-master-standard.md
references/usage-routing.md
references/quality-checklist.md
Then load only the inherited docs, scripts, assets, or examples that match the user's actual task.
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
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: tdd-workflows-tdd-cycle3description: ALWAYS use this when the request matches TDD Workflows TDD Cycle: Use when working with tdd workflows tdd cycle4---56## Selective Reading Rule78Start with:910- `references/senior-master-standard.md`11- `references/usage-routing.md`12- `references/quality-checklist.md`1314Then load only the inherited docs, scripts, assets, or examples that match the user's actual task.1516## Use this skill when1718- Working on tdd workflows tdd cycle tasks or workflows19- Needing guidance, best practices, or checklists for tdd workflows tdd cycle2021## Do not use this skill when2223- The task is unrelated to tdd workflows tdd cycle24- You need a different domain or tool outside this scope2526## Instructions2728- Clarify goals, constraints, and required inputs.29- Apply relevant best practices and validate outcomes.30- Provide actionable steps and verification.31- If detailed examples are required, open `resources/implementation-playbook.md`.3233Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:3435[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.]3637## Configuration3839### Coverage Thresholds40- Minimum line coverage: 80%41- Minimum branch coverage: 75%42- Critical path coverage: 100%4344### Refactoring Triggers45- Cyclomatic complexity > 1046- Method length > 20 lines47- Class length > 200 lines48- Duplicate code blocks > 3 lines4950## Phase 1: Test Specification and Design5152### 1. Requirements Analysis53- Use Task tool with subagent_type="comprehensive-review::architect-review"54- Prompt: "Analyze requirements for: $ARGUMENTS. Define acceptance criteria, identify edge cases, and create test scenarios. Output a comprehensive test specification."55- Output: Test specification, acceptance criteria, edge case matrix56- Validation: Ensure all requirements have corresponding test scenarios5758### 2. Test Architecture Design59- Use Task tool with subagent_type="unit-testing::test-automator"60- Prompt: "Design test architecture for: $ARGUMENTS based on test specification. Define test structure, fixtures, mocks, and test data strategy. Ensure testability and maintainability."61- Output: Test architecture, fixture design, mock strategy62- Validation: Architecture supports isolated, fast, reliable tests6364## Phase 2: RED - Write Failing Tests6566### 3. Write Unit Tests (Failing)67- Use Task tool with subagent_type="unit-testing::test-automator"68- Prompt: "Write FAILING unit tests for: $ARGUMENTS. Tests must fail initially. Include edge cases, error scenarios, and happy paths. DO NOT implement production code."69- Output: Failing unit tests, test documentation70- **CRITICAL**: Verify all tests fail with expected error messages7172### 4. Verify Test Failure73- Use Task tool with subagent_type="tdd-workflows::code-reviewer"74- 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."75- Output: Test failure verification report76- **GATE**: Do not proceed until all tests fail appropriately7778## Phase 3: GREEN - Make Tests Pass7980### 5. Minimal Implementation81- Use Task tool with subagent_type="backend-development::backend-architect"82- 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."83- Output: Minimal working implementation84- Constraint: No code beyond what's needed to pass tests8586### 6. Verify Test Success87- Use Task tool with subagent_type="unit-testing::test-automator"88- Prompt: "Run all tests for: $ARGUMENTS and verify they pass. Check test coverage metrics. Ensure no tests were accidentally broken."89- Output: Test execution report, coverage metrics90- **GATE**: All tests must pass before proceeding9192## Phase 4: REFACTOR - Improve Code Quality9394### 7. Code Refactoring95- Use Task tool with subagent_type="tdd-workflows::code-reviewer"96- Prompt: "Refactor implementation for: $ARGUMENTS while keeping tests green. Apply SOLID principles, remove duplication, improve naming, and optimize performance. Run tests after each refactoring."97- Output: Refactored code, refactoring report98- Constraint: Tests must remain green throughout99100### 8. Test Refactoring101- Use Task tool with subagent_type="unit-testing::test-automator"102- Prompt: "Refactor tests for: $ARGUMENTS. Remove test duplication, improve test names, extract common fixtures, and enhance test readability. Ensure tests still provide same coverage."103- Output: Refactored tests, improved test structure104- Validation: Coverage metrics unchanged or improved105106## Phase 5: Integration and System Tests107108### 9. Write Integration Tests (Failing First)109- Use Task tool with subagent_type="unit-testing::test-automator"110- Prompt: "Write FAILING integration tests for: $ARGUMENTS. Test component interactions, API contracts, and data flow. Tests must fail initially."111- Output: Failing integration tests112- Validation: Tests fail due to missing integration logic113114### 10. Implement Integration115- Use Task tool with subagent_type="backend-development::backend-architect"116- Prompt: "Implement integration code for: $ARGUMENTS to make integration tests pass. Focus on component interaction and data flow."117- Output: Integration implementation118- Validation: All integration tests pass119120## Phase 6: Continuous Improvement Cycle121122### 11. Performance and Edge Case Tests123- Use Task tool with subagent_type="unit-testing::test-automator"124- Prompt: "Add performance tests and additional edge case tests for: $ARGUMENTS. Include stress tests, boundary tests, and error recovery tests."125- Output: Extended test suite126- Metric: Increased test coverage and scenario coverage127128### 12. Final Code Review129- Use Task tool with subagent_type="comprehensive-review::architect-review"130- Prompt: "Perform comprehensive review of: $ARGUMENTS. Verify TDD process was followed, check code quality, test quality, and coverage. Suggest improvements."131- Output: Review report, improvement suggestions132- Action: Implement critical suggestions while maintaining green tests133134## Incremental Development Mode135136For test-by-test development:1371. Write ONE failing test1382. Make ONLY that test pass1393. Refactor if needed1404. Repeat for next test141142Use this approach by adding `--incremental` flag to focus on one test at a time.143144## Test Suite Mode145146For comprehensive test suite development:1471. Write ALL tests for a feature/module (failing)1482. Implement code to pass ALL tests1493. Refactor entire module1504. Add integration tests151152Use this approach by adding `--suite` flag for batch test development.153154## Validation Checkpoints155156### RED Phase Validation157- [ ] All tests written before implementation158- [ ] All tests fail with meaningful error messages159- [ ] Test failures are due to missing implementation160- [ ] No test passes accidentally161162### GREEN Phase Validation163- [ ] All tests pass164- [ ] No extra code beyond test requirements165- [ ] Coverage meets minimum thresholds166- [ ] No test was modified to make it pass167168### REFACTOR Phase Validation169- [ ] All tests still pass after refactoring170- [ ] Code complexity reduced171- [ ] Duplication eliminated172- [ ] Performance improved or maintained173- [ ] Test readability improved174175## Coverage Reports176177Generate coverage reports after each phase:178- Line coverage179- Branch coverage180- Function coverage181- Statement coverage182183## Failure Recovery184185If TDD discipline is broken:1861. **STOP** immediately1872. Identify which phase was violated1883. Rollback to last valid state1894. Resume from correct phase1905. Document lesson learned191192## TDD Metrics Tracking193194Track and report:195- Time in each phase (Red/Green/Refactor)196- Number of test-implementation cycles197- Coverage progression198- Refactoring frequency199- Defect escape rate200201## Anti-Patterns to Avoid202203- Writing implementation before tests204- Writing tests that already pass205- Skipping the refactor phase206- Writing multiple features without tests207- Modifying tests to make them pass208- Ignoring failing tests209- Writing tests after implementation210211## Success Criteria212213- 100% of code written test-first214- All tests pass continuously215- Coverage exceeds thresholds216- Code complexity within limits217- Zero defects in covered code218- Clear test documentation219- Fast test execution (< 5 seconds for unit tests)220221## Notes222223- Enforce strict RED-GREEN-REFACTOR discipline224- Each phase must be completed before moving to next225- Tests are the specification226- If a test is hard to write, the design needs improvement227- Refactoring is NOT optional228- Keep test execution fast229- Tests should be independent and isolated230231TDD implementation for: $ARGUMENTS232233## Limitations234- Use this skill only when the task clearly matches the scope described above.235- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.236- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.