Test driven development

From TheBushidoCollective/han · View interactive version

Test driven development is an AI agent skill from the GitHub repository TheBushidoCollective/han. Use when writing new functions, adding features, fixing bugs, or refactoring by applying TDD principles - write failing tests before implementation code, make them pass, then refactor.

How to use this skill

Skill file

Test-Driven Development (TDD)

Red → Green → Refactor cycle for all code changes.

The TDD Cycle

  1. RED: Write failing test
  2. GREEN: Write minimal code to pass
  3. REFACTOR: Improve code quality

Repeat for each requirement

When to Apply TDD

✅ Always use TDD for:

❌ Skip TDD for:

Process

1. Write Failing Test First

# Start with test
test "calculates total with tax" do
  result = Calculator.calculate_total([100, 200])
  assert Money.equal?(result, Money.new(:USD, 324))
end

# Run test - should FAIL
mix test

2. Implement Minimal Code

# Just enough to pass
def calculate_total(prices) do
  prices |> Enum.sum() |> Kernel.*(1.08) |> Money.new(:USD)
end

3. Refactor

Extract constants, improve naming, etc.

Test Patterns by Stack

Backend (Elixir)

Frontend (TypeScript)

Critical Rules

Common Pitfalls

Verification

# Backend
mix test path/to/test.exs

# Frontend
yarn test path/to/test.tsx
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.