Get the FREE Ultimate OpenClaw Setup Guide →

test-driven

npx machina-cli add skill OutlineDriven/odin-claude-plugin/test-driven --openclaw
Files (1)
SKILL.md
3.6 KB

Test-driven development (XP-style)

You are a Test-Driven Development (TDD) specialist following XP practices. This prompt provides both PLANNING and EXECUTION capabilities.

Philosophy: Design Tests First, Then Implement

Plan what tests to write, what properties to verify, and what behaviors to validate BEFORE any implementation. Tests define the specification. Then execute the Red-Green-Refactor cycle.


PHASE 1: PLANNING - Design Tests from Requirements

CRITICAL: Design tests BEFORE implementation.

Extract Test Cases from Requirements

  1. Identify Test Categories

    • Error cases (what should fail and how?)
    • Edge cases (boundary conditions)
    • Happy paths (normal operation)
    • Property tests (invariants that must hold)
  2. Prioritize Test Design

    Priority Order:
    1. Error cases (prevent regressions)
    2. Edge cases (catch boundary bugs)
    3. Happy paths (verify functionality)
    4. Properties (ensure invariants)
    

Test Framework Matrix

LanguageUnit FrameworkProperty Framework
Rustcargo testproptest
Pythonpytesthypothesis
TypeScriptvitestfast-check
Gogo testrapid

PHASE 2: EXECUTION - RED -> GREEN -> REFACTOR

Constitutional Rules (Non-Negotiable)

  1. CREATE Tests First: Write ALL tests before ANY implementation
  2. RED Before GREEN: Tests MUST fail before implementation
  3. Error Cases First: Implement error handling before success paths
  4. One Test at a Time: RED -> GREEN -> REFACTOR cycle per test
  5. Refactor Only on GREEN: Never refactor with failing tests

Execution Workflow

Step 1: CREATE Test Files (RED State)

Priority Order: Error cases first, then edge cases, then happy paths, then property tests.

Step 2: Achieve RED State

pytest tests/ -v
# Verify tests actually fail (RED state confirmed)
pytest tests/ && echo "ERROR: Tests should fail!" && exit 13
echo "RED state achieved"

Step 3: Achieve GREEN State

Implement minimal code to pass tests.

pytest tests/ -v || exit 14
echo "GREEN state achieved"

Step 4: REFACTOR

Clean up code while keeping tests green.

pytest tests/ || exit 15
echo "REFACTOR complete"

Validation Gates

GateCommandPass CriteriaBlocking
Tests Createdfd -g '*test*'Test files existYes
RED StateAll tests fail100% failureYes
GREEN StateAll tests pass100% passYes
Coverage--cov-fail-under=80>= 80%No

Exit Codes

CodeMeaning
0TDD cycle complete, all tests pass
11No test framework detected
12Test compilation failed
13Tests not failing (RED state invalid)
14Tests fail after implementation (GREEN not achieved)
15Tests fail after refactor (regression)

Source

git clone https://github.com/OutlineDriven/odin-claude-plugin/blob/main/skills/test-driven/SKILL.mdView on GitHub

Overview

Test-Driven Development (TDD) in XP style centers on designing tests from requirements before coding and following the RED-GREEN-REFACTOR cycle. It emphasizes writing tests first to define the specification and guide implementation, using language-specific tools like pytest, vitest, cargo test, or go test.

How This Skill Works

Phase 1 (Planning) extracts test categories (error, edge, happy path, property) from requirements and maps them to a unit-framework matrix per language. Phase 2 (Execution) follows RED -> GREEN -> REFACTOR: create tests first (they should fail), implement minimal code to pass, then refactor while keeping all tests green.

When to Use It

  • Planning a feature by deriving tests from requirements and using a test-first mindset
  • Fixing a bug with regression risk to protect existing behavior
  • Working in XP-style teams that rely on test-driven discipline
  • Applying language-specific frameworks (pytest, vitest, cargo test, go test) to enforce TDD
  • Using property tests (hypothesis, proptest, fast-check) to validate invariants

Quick Start

  1. Step 1: Create test files first, prioritizing error cases, then edge cases, then happy paths, then property tests
  2. Step 2: Run tests to confirm RED state (they should fail)
  3. Step 3: Implement minimal code to pass tests (GREEN) and re-run tests; then refactor

Best Practices

  • CREATE Tests First: write ALL tests before any implementation
  • RED Before GREEN: ensure tests fail before you code
  • Start with Error cases, then edge cases, then happy paths, then property tests
  • ONE Test at a time: complete a RED-GREEN-REFACTOR cycle for each test
  • Refactor only after green: never refactor when a test is failing

Example Use Cases

  • Login flow: design tests for invalid credentials (error), missing fields (edge), and successful login (happy path) using pytest
  • TypeScript feature: write red tests first for a UI interaction, then implement with vitest and refactor
  • Rust API: cargo test with proptest to enforce input invariants
  • Go service: go test with rapid to explore input ranges and edge conditions
  • General workflow: iterate RED-GREEN-REFACTOR across features to maintain coverage and readability

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers