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
🏰 Rei Skills — Curated by Rootcastle Engineering & Innovation | Batuhan Ayrıbaş
Engineering Beyond Boundaries | admin@rootcastle.com
1---2name: tdd-workflows-tdd-cycle3description: "Use when working with tdd workflows tdd cycle"4risk: unknown5source: rootcastle-rei6metadata:7 source: https://skillmd.com/skills/rootcastleco/tdd-workflows-tdd-cycle8---910## Use this skill when1112- Working on tdd workflows tdd cycle tasks or workflows13- Needing guidance, best practices, or checklists for tdd workflows tdd cycle1415## Do not use this skill when1617- The task is unrelated to tdd workflows tdd cycle18- You need a different domain or tool outside this scope1920## Instructions2122- Clarify goals, constraints, and required inputs.23- Apply relevant best practices and validate outcomes.24- Provide actionable steps and verification.25- If detailed examples are required, open `resources/implementation-playbook.md`.2627Execute a comprehensive Test-Driven Development (TDD) workflow with strict red-green-refactor discipline:2829[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.]3031## Configuration3233### Coverage Thresholds34- Minimum line coverage: 80%35- Minimum branch coverage: 75%36- Critical path coverage: 100%3738### Refactoring Triggers39- Cyclomatic complexity > 1040- Method length > 20 lines41- Class length > 200 lines42- Duplicate code blocks > 3 lines4344## Phase 1: Test Specification and Design4546### 1. Requirements Analysis47- Use Task tool with subagent_type="comprehensive-review::architect-review"48- Prompt: "Analyze requirements for: $ARGUMENTS. Define acceptance criteria, identify edge cases, and create test scenarios. Output a comprehensive test specification."49- Output: Test specification, acceptance criteria, edge case matrix50- Validation: Ensure all requirements have corresponding test scenarios5152### 2. Test Architecture Design53- Use Task tool with subagent_type="unit-testing::test-automator"54- Prompt: "Design test architecture for: $ARGUMENTS based on test specification. Define test structure, fixtures, mocks, and test data strategy. Ensure testability and maintainability."55- Output: Test architecture, fixture design, mock strategy56- Validation: Architecture supports isolated, fast, reliable tests5758## Phase 2: RED - Write Failing Tests5960### 3. Write Unit Tests (Failing)61- Use Task tool with subagent_type="unit-testing::test-automator"62- Prompt: "Write FAILING unit tests for: $ARGUMENTS. Tests must fail initially. Include edge cases, error scenarios, and happy paths. DO NOT implement production code."63- Output: Failing unit tests, test documentation64- **CRITICAL**: Verify all tests fail with expected error messages6566### 4. Verify Test Failure67- Use Task tool with subagent_type="tdd-workflows::code-reviewer"68- 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."69- Output: Test failure verification report70- **GATE**: Do not proceed until all tests fail appropriately7172## Phase 3: GREEN - Make Tests Pass7374### 5. Minimal Implementation75- Use Task tool with subagent_type="backend-development::backend-architect"76- 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."77- Output: Minimal working implementation78- Constraint: No code beyond what's needed to pass tests7980### 6. Verify Test Success81- Use Task tool with subagent_type="unit-testing::test-automator"82- Prompt: "Run all tests for: $ARGUMENTS and verify they pass. Check test coverage metrics. Ensure no tests were accidentally broken."83- Output: Test execution report, coverage metrics84- **GATE**: All tests must pass before proceeding8586## Phase 4: REFACTOR - Improve Code Quality8788### 7. Code Refactoring89- Use Task tool with subagent_type="tdd-workflows::code-reviewer"90- Prompt: "Refactor implementation for: $ARGUMENTS while keeping tests green. Apply SOLID principles, remove duplication, improve naming, and optimize performance. Run tests after each refactoring."91- Output: Refactored code, refactoring report92- Constraint: Tests must remain green throughout9394### 8. Test Refactoring95- Use Task tool with subagent_type="unit-testing::test-automator"96- Prompt: "Refactor tests for: $ARGUMENTS. Remove test duplication, improve test names, extract common fixtures, and enhance test readability. Ensure tests still provide same coverage."97- Output: Refactored tests, improved test structure98- Validation: Coverage metrics unchanged or improved99100## Phase 5: Integration and System Tests101102### 9. Write Integration Tests (Failing First)103- Use Task tool with subagent_type="unit-testing::test-automator"104- Prompt: "Write FAILING integration tests for: $ARGUMENTS. Test component interactions, API contracts, and data flow. Tests must fail initially."105- Output: Failing integration tests106- Validation: Tests fail due to missing integration logic107108### 10. Implement Integration109- Use Task tool with subagent_type="backend-development::backend-architect"110- Prompt: "Implement integration code for: $ARGUMENTS to make integration tests pass. Focus on component interaction and data flow."111- Output: Integration implementation112- Validation: All integration tests pass113114## Phase 6: Continuous Improvement Cycle115116### 11. Performance and Edge Case Tests117- Use Task tool with subagent_type="unit-testing::test-automator"118- Prompt: "Add performance tests and additional edge case tests for: $ARGUMENTS. Include stress tests, boundary tests, and error recovery tests."119- Output: Extended test suite120- Metric: Increased test coverage and scenario coverage121122### 12. Final Code Review123- Use Task tool with subagent_type="comprehensive-review::architect-review"124- Prompt: "Perform comprehensive review of: $ARGUMENTS. Verify TDD process was followed, check code quality, test quality, and coverage. Suggest improvements."125- Output: Review report, improvement suggestions126- Action: Implement critical suggestions while maintaining green tests127128## Incremental Development Mode129130For test-by-test development:1311. Write ONE failing test1322. Make ONLY that test pass1333. Refactor if needed1344. Repeat for next test135136Use this approach by adding `--incremental` flag to focus on one test at a time.137138## Test Suite Mode139140For comprehensive test suite development:1411. Write ALL tests for a feature/module (failing)1422. Implement code to pass ALL tests1433. Refactor entire module1444. Add integration tests145146Use this approach by adding `--suite` flag for batch test development.147148## Validation Checkpoints149150### RED Phase Validation151- [ ] All tests written before implementation152- [ ] All tests fail with meaningful error messages153- [ ] Test failures are due to missing implementation154- [ ] No test passes accidentally155156### GREEN Phase Validation157- [ ] All tests pass158- [ ] No extra code beyond test requirements159- [ ] Coverage meets minimum thresholds160- [ ] No test was modified to make it pass161162### REFACTOR Phase Validation163- [ ] All tests still pass after refactoring164- [ ] Code complexity reduced165- [ ] Duplication eliminated166- [ ] Performance improved or maintained167- [ ] Test readability improved168169## Coverage Reports170171Generate coverage reports after each phase:172- Line coverage173- Branch coverage174- Function coverage175- Statement coverage176177## Failure Recovery178179If TDD discipline is broken:1801. **STOP** immediately1812. Identify which phase was violated1823. Rollback to last valid state1834. Resume from correct phase1845. Document lesson learned185186## TDD Metrics Tracking187188Track and report:189- Time in each phase (Red/Green/Refactor)190- Number of test-implementation cycles191- Coverage progression192- Refactoring frequency193- Defect escape rate194195## Anti-Patterns to Avoid196197- Writing implementation before tests198- Writing tests that already pass199- Skipping the refactor phase200- Writing multiple features without tests201- Modifying tests to make them pass202- Ignoring failing tests203- Writing tests after implementation204205## Success Criteria206207- 100% of code written test-first208- All tests pass continuously209- Coverage exceeds thresholds210- Code complexity within limits211- Zero defects in covered code212- Clear test documentation213- Fast test execution (< 5 seconds for unit tests)214215## Notes216217- Enforce strict RED-GREEN-REFACTOR discipline218- Each phase must be completed before moving to next219- Tests are the specification220- If a test is hard to write, the design needs improvement221- Refactoring is NOT optional222- Keep test execution fast223- Tests should be independent and isolated224225TDD implementation for: $ARGUMENTS226227---228229> 🏰 **Rei Skills** — Curated by [Rootcastle Engineering & Innovation](https://www.rootcastle.com) | Batuhan Ayrıbaş 230> Engineering Beyond Boundaries | admin@rootcastle.com