Test driven development

From elophanto/EloPhanto · View interactive version

Test driven development is an AI agent skill from the GitHub repository elophanto/EloPhanto. Enforces the Red-Green-Refactor TDD cycle. Write a failing test first, implement minimal code to pass, then refactor. Prevents writing code before tests exist.

How to use this skill

Skill file

Triggers

Instructions

The Red-Green-Refactor Cycle

You MUST follow this exact cycle for every piece of functionality:

Step 1: RED — Write a failing test

Before writing ANY implementation code, write a test that:

# Run the test and VERIFY it fails
shell_execute: pytest tests/test_feature.py -v
# Expected: FAILED (red)

If the test passes without implementation, your test is wrong. Delete it

and write a better one that actually tests the new behavior.

Step 2: GREEN — Write minimal code to pass

Write the MINIMUM code needed to make the test pass. Not more.

Rules:

# Run the test and VERIFY it passes
shell_execute: pytest tests/test_feature.py -v
# Expected: PASSED (green)
Step 3: REFACTOR — Clean up while green

Now that the test passes, improve the code:

After EVERY change, run the test again:

shell_execute: pytest tests/test_feature.py -v
# Expected: still PASSED (green)

If the test breaks during refactoring, undo and try a smaller change.

Critical Rules

  1. NEVER write implementation before the test. If you catch yourself

writing a function before its test exists, STOP. Delete the function.

Write the test first.

  1. NEVER skip the RED step. You must observe the test failing before

writing implementation. This verifies the test actually tests something.

  1. One test at a time. Don't write 10 tests then implement. Write ONE

test, make it pass, then write the next test.

  1. Tests must be specific. assert result is not None is not a test.

assert result == {"status": "ok", "count": 3} is a test.

  1. Run tests after EVERY change. Not after 5 changes. After every

single change. The test suite is your safety net — use it constantly.

  1. If you break existing tests, fix them FIRST. Don't continue adding

features with broken tests in the background.

Test File Organization

project/
  src/
    feature.py          # Implementation
  tests/
    test_feature.py     # Tests for feature.py
    conftest.py         # Shared fixtures

Common Testing Patterns

Arrange-Act-Assert:

def test_user_creation():
    # Arrange
    data = {"name": "Alice", "email": "alice@example.com"}

    # Act
    user = create_user(data)

    # Assert
    assert user.name == "Alice"
    assert user.email == "alice@example.com"
    assert user.id is not None

Testing exceptions:

def test_invalid_email_raises():
    with pytest.raises(ValueError, match="invalid email"):
        create_user({"name": "Alice", "email": "not-an-email"})

Testing side effects:

def test_send_welcome_email(mocker):
    mock_send = mocker.patch("app.email.send")
    create_user({"name": "Alice", "email": "alice@example.com"})
    mock_send.assert_called_once_with("alice@example.com", subject="Welcome!")

Framework Commands

| Language | Run Tests | Watch Mode |

|----------|----------|------------|

| Python | pytest -v | pytest-watch |

| JavaScript | npm test | npm test -- --watch |

| TypeScript | npx jest --verbose | npx jest --watch |

| Rust | cargo test | cargo watch -x test |

| Go | go test ./... | gotestsum --watch |

Tools to Use

When NOT to Use TDD

For everything else: Red. Green. Refactor. Every time.

Verify

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.