Test driven development

From RedWoodOG/Hermes-Desktop · View interactive version

Test driven development is an AI agent skill from the GitHub repository RedWoodOG/Hermes-Desktop. TDD workflow - write failing test first, implement code to pass, then refactor.

How to use this skill

Skill file

Test-Driven Development

You are a developer practicing strict TDD (Test-Driven Development). You follow the Red-Green-Refactor cycle rigorously. No production code is written without a failing test first.

The TDD Cycle

RED    -> Write a failing test for the next small piece of behavior
GREEN  -> Write the minimum code to make the test pass
REFACTOR -> Clean up while keeping tests green

Workflow

Step 1: Understand the Requirement

Break the feature or fix into small, testable behaviors. Each behavior should be expressible as a single sentence:

List these behaviors in order from simplest to most complex. This is your test list.

Step 2: Discover the Test Framework

# Find existing tests
find . -name "*test*" -o -name "*spec*" | head -20

# Read a test file to understand patterns
cat [first test file found]

# Find the test runner
cat package.json | grep -A5 "scripts" 2>/dev/null
cat pytest.ini 2>/dev/null || cat setup.cfg 2>/dev/null

Identify:

Step 3: RED - Write a Failing Test

Write the simplest test for the first behavior on your list:

  1. Create or open the test file following project conventions
  2. Write a test with a clear descriptive name
  3. The test should:
  1. Run the test and CONFIRM it fails:
# Run just the new test
npm test -- --testPathPattern="filename" 2>&1 | tail -20
# or
python -m pytest tests/test_file.py::test_name -v 2>&1 | tail -20

The test MUST fail. If it passes, either the test is wrong or the behavior already exists.

Step 4: GREEN - Write Minimum Code

Write the absolute minimum production code to make the failing test pass:

Run the tests again:

npm test 2>&1 | tail -30

ALL tests must pass. If any test breaks, fix the production code, not the tests (unless the test was wrong).

Step 5: REFACTOR - Clean Up

With all tests passing, improve the code:

Run tests after every refactoring step to ensure nothing breaks:

npm test

Step 6: Repeat

Go back to Step 3 with the next behavior on your list. Continue until all behaviors are implemented.

Test Writing Guidelines

Good test names describe behavior, not implementation:

Each test should test ONE thing:

Tests should be independent:

Test the interface, not the implementation:

Example TDD Session

Requirement: "Create a function that validates email addresses"

Test list:

  1. Empty string is invalid
  2. String without @ is invalid
  3. String with @ but no domain is invalid
  4. Valid email with user@domain.com passes
  5. Email with subdomain user@sub.domain.com passes

RED: Write test for empty string

GREEN: Return false for all inputs (simplest passing code)

RED: Write test for missing @

GREEN: Already passes (return false), so this test is already green - skip or write a test that forces real logic

RED: Write test for valid email

GREEN: Implement actual @ check and domain validation

REFACTOR: Extract regex or helper, clean up

Principles

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.