Test driven development

From 5throck/ai-workspace-standards · View interactive version

Test driven development is an AI agent skill from the GitHub repository 5throck/ai-workspace-standards. Implements software using Test-Driven Development (TDD) methodology with red-green-refactor cycle. Use when: developing new features, fixing bugs with tests, or ensuring code reliability through test-first approach.

How to use this skill

Skill file

Context

This skill provides systematic Test-Driven Development (TDD) workflow, ensuring code quality and reliability through the red-green-refactor cycle. It emphasizes writing tests before implementation, leading to more maintainable, better-designed code.

When to Use

Feature Development:

Bug Fixing:

Code Refactoring:

Quality Assurance:


Execution Steps

Step 1: Red - Write a Failing Test

Purpose: Start by defining what success looks like.

Test Writing Process:

  1. Understand Requirements:
  1. Write Test Specification:
  1. Run Test - Verify Failure:

Test Quality Checklist:

Example Test Structure:

def test_calculator_adds_two_numbers():
    # Arrange
    calculator = Calculator()
    
    # Act
    result = calculator.add(2, 3)
    
    # Assert
    assert result == 5

Step 2: Green - Make Test Pass

Purpose: Write minimal code to pass the test.

Implementation Strategy:

  1. Write Minimal Implementation:
  1. Run Test - Verify Success:
  1. Keep It Simple:

Green Phase Principles:

Common Mistakes:


Step 3: Refactor - Improve Code

Purpose: Clean up code while keeping tests green.

Refactoring Process:

  1. Run All Tests:
  1. Apply Refactoring:
  1. Run Tests After Each Change:

Refactoring Checklist:

Refactoring Techniques:

Safe Refactoring:


Step 4: Repeat the Cycle

Purpose: Build comprehensive test coverage incrementally.

Iteration Strategy:

  1. Next Test Case:
  1. Build Up Behavior:
  1. Coverage Goals:

Test Pyramid:

    E2E Tests (few)
       /\
      /  \
     /    \
    /      \
   /        \
  / Integration \
 /   Tests     \
/______________\
Unit Tests (many)

Step 5: Test Quality Standards

Purpose: Ensure tests provide long-term value.

Good Test Characteristics:

  1. Readability:
  1. Maintainability:
  1. Usefulness:

Test Organization:

Anti-Patterns to Avoid:


Step 6: TDD Best Practices

Purpose: Apply TDD effectively in real projects.

Starting TDD:

  1. Begin with Simple Cases:
  1. Test First Mindset:
  1. Keep Tests Fast:

Common Challenges:

TDD in Legacy Code:

  1. Add tests around existing code (characterization tests)
  2. Refactor in small steps with test safety net
  3. Gradually improve test coverage
  4. Use tests to guide refactoring

Output Format

For Feature Development:

For Bug Fixes:

For Refactoring:


Best Practices

TDD Discipline:

✅ Do:

❌ Don't:

Test Quality:

✅ Do:

❌ Don't:


Common Mistakes to Avoid

TDD Anti-Patterns:

  1. Fake TDD: Writing tests after code ("green-red-refactor")
  2. Test-Induced Design: Over-engineering for testability
  3. Coverage Obsession: Focusing on metrics over value
  4. Testing Trivia: Testing getters/setters or simple methods
  5. Fragile Tests: Tests that break with implementation changes

Process Anti-Patterns:

  1. Skipping Red: Not verifying test fails first
  2. Skipping Refactor: Leaving code messy after green
  3. Big Steps: Writing too much code between tests
  4. Test Dependencies: Tests that require specific order
  5. Slow Tests: Tests that discourage frequent running

Spoke Derivation Note

This file is the hub-doctrine canonical for the co-develop generic dev spine

(spec 2026-11-01-hub-consolidation-design, Phase 1 batch D). Co-develop

pipelines run it as written. A spoke variant derives from this doctrine by

substituting the bindings below — the derivation never edits the

single-valued frontmatter doctrine: scope: co-develop stays as written

here, and the spoke label lives in this note only.

No {{PROJECT_*}} placeholder is needed in this skill: its per-spoke deltas

are frontmatter labels, not body prose, so they are documented as bindings

rather than parameterized.

| Spoke | Derivation binding |

|---|---|

| co-game | Ships byte-identical to co-develop, including scope: co-develop (merge ruling 2026-11-06, DEC-20261106-03: diverged same-version copies are merged, not split by version bump); no per-spoke scope rendering. |

| co-learning | Not adopted — absent from Projects/co-learning and its template. The fleet skill-graph projection carries only a dangling reference node for it (content_hash null); it is not an installed consumer. |

| co-abap | Not adopted — co-abap carries no TDD capability; its SAP quality chain (RunUnitTests/ATC via the test-runner agent) is a domain-specific workflow outside this generic spine. |


Related Skills


TDD Tools and Frameworks

Popular Testing Frameworks:

Test Doubles Libraries:

Coverage Tools:


Testing Strategies

Unit Testing:

Integration Testing:

E2E Testing:

Property-Based Testing:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.