agentleFS
bostonaholicbostonaholic/rpikit/skills/test-driven-development/SKILL.md

test-driven-development

Skill19 starsChanged 8 months agoMITView on GitHub

Rigorous TDD methodology enforcing RED-GREEN-REFACTOR discipline. Use when implementing features or fixing bugs during the implement phase. Tests must be written before production code - no exceptions.

190 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use chinese-code-review, chinese-commit-conventions and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Leodorareluctant259Skill

    chinese-code-review

    中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈

    Also in 8 projects that use this

  • Leodorareluctant259Skill

    chinese-commit-conventions

    中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化

    Also in 8 projects that use this

  • obraSkill

    diagnosing-superpowers

    Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

    Also in 19 projects that use this

  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 39 projects that use this

  • LLl0k0laDSkill

    git-workflow-and-versioning

    Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

    Also in 47 projects that use this

  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 15 projects that use this

  • +3 more from Leodorareluctant259
  • +3 more from LLl0k0laD

The file

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. 0 are common, 23 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 178 edited versions we read keep these.

  • 23

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write tests first, then implementation.

    line 11
  2. Distinctive:

    If you write code before the test, you must delete it and start over.

    line 23
  3. Distinctive:

    Write ONE minimal test that demonstrates the required behavior:

    line 30
  4. Distinctive:

    Test the public interface, not internals

    line 32
  5. Distinctive:

    Never mock what you can use for real

    line 33
  6. Distinctive:

    Run the test - it MUST fail

    line 35
  7. Distinctive:

    If the test passes immediately, you've written it wrong or the feature already exists.

    line 48
  8. Distinctive:

    Write the SIMPLEST code that makes the test pass:

    line 52
  9. Distinctive:

    When executing plan steps that involve code:

    line 129
  10. Distinctive:

    Before coding: Write failing test for the behavior

    line 131
  11. Distinctive:

    Verify RED: Test fails for the right reason

    line 132
  12. Distinctive:

    Verify GREEN: Test passes, no regressions

    line 134
  13. Distinctive:

    Mark complete: Only after tests pass

    line 136
  14. Distinctive:

    If a plan step doesn't mention tests, add them anyway.

    line 138
  15. Distinctive:

    Don't depend on external state

    line 147
  16. Distinctive:

    Test private methods directly

    line 152
  17. Distinctive:

    Wrong: Write feature, then write tests to cover it

    line 173
  18. Distinctive:

    Right: Write test, watch it fail, then write feature

    line 174
  19. Distinctive:

    Right: Run test, observe failure, understand why

    line 184
  20. Distinctive:

    Right: Never mock what you can use for real

    line 189
  21. Distinctive:

    Wrong: Test that internal method X calls internal method Y

    line 193
  22. Distinctive:

    Right: Test that public interface produces correct results

    line 194
  23. Distinctive:

    Before marking a step complete:

    line 198

“Common” is measured: kept by at least 6 in 10 of the 178 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Test-Driven Development

Write tests first, then implementation. No production code without a failing test.

Purpose

TDD ensures code correctness through disciplined test-first development. Tests written after implementation prove nothing - they pass immediately, providing no evidence the code works correctly. This skill enforces the RED-GREEN-REFACTOR cycle as a non-negotiable practice.

The Iron Law

NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST.

If you write code before the test, you must delete it and start over. The test drives the implementation, not the other way around.

The Cycle

RED: Write a Failing Test

Write ONE minimal test that demonstrates the required behavior:

  1. Test the public interface, not internals
  2. Never mock what you can use for real
  3. Name the test to describe the behavior
  4. Run the test - it MUST fail

Mandatory verification:

Run the test. Confirm it fails for the RIGHT reason:
- Missing function/method (expected)
- Wrong return value (expected)
- NOT: Syntax error
- NOT: Import error
- NOT: Test framework misconfiguration

If the test passes immediately, you've written it wrong or the feature already exists. Investigate before proceeding.

GREEN: Write Minimal Code

Write the SIMPLEST code that makes the test pass:

  1. No extra features
  2. No premature optimization
  3. No "while I'm here" additions
  4. Just enough to satisfy the test

Mandatory verification:

Run the test. Confirm:
- The new test passes
- All other tests still pass
- No new warnings or errors

REFACTOR: Improve Without Breaking

Improve code quality while keeping tests green:

  1. Remove duplication
  2. Improve names
  3. Extract helpers
  4. Simplify logic

After each change:

Run all tests. They must still pass.
If any test fails, revert the refactor.

Cycle Example

Requirement: Function that validates email addresses

RED:
  Write test: expect(isValidEmail("user@example.com")).toBe(true)
  Run test: FAIL - isValidEmail is not defined
  Correct failure reason: function doesn't exist yet

GREEN:
  Write: function isValidEmail(email) { return true; }
  Run test: PASS
  All tests pass

RED:
  Write test: expect(isValidEmail("invalid")).toBe(false)
  Run test: FAIL - Expected false, got true
  Correct failure reason: no validation logic yet

GREEN:
  Write: function isValidEmail(email) { return email.includes("@"); }
  Run test: PASS
  All tests pass

REFACTOR:
  Extract regex pattern to constant
  Run tests: PASS
  Continue improving...

Common Rationalizations (Reject All)

RationalizationReality
"I'll write tests after"Tests written after pass immediately, proving nothing
"This is too simple to test"Simple things become complex. Test it.
"I know this works"Prove it with a test
"Testing slows me down"Debugging untested code takes longer
"I'll just try it manually"Manual testing isn't repeatable or systematic
"The code is obvious"Make it obviously correct with a test
"I already wrote the code"Delete it. Start with the test.

Integration with Implement Phase

When executing plan steps that involve code:

  1. Before coding: Write failing test for the behavior
  2. Verify RED: Test fails for the right reason
  3. Write code: Minimal implementation
  4. Verify GREEN: Test passes, no regressions
  5. Refactor: Improve while green
  6. Mark complete: Only after tests pass

If a plan step doesn't mention tests, add them anyway. TDD is not optional.

Test Quality Guidelines

Good Tests

  • Describe behavior, not implementation
  • Fail for one reason only
  • Run fast (milliseconds)
  • Don't depend on external state
  • Read like specifications

Bad Tests

  • Test private methods directly
  • Require specific execution order
  • Mock what you can use for real (indicates bad design)
  • Pass without verifying anything meaningful
  • Break when refactoring internals

Edge Cases and Boundaries

Test these explicitly:

  • Empty inputs
  • Null/undefined values
  • Boundary values (0, -1, MAX_INT)
  • Invalid inputs
  • Error conditions
  • Concurrent access (if applicable)

Anti-Patterns

Writing Code First

Wrong: Write feature, then write tests to cover it Right: Write test, watch it fail, then write feature

Testing After the Fact

Wrong: "I'll add tests in a follow-up PR" Right: Tests are part of the implementation, not separate

Skipping RED Verification

Wrong: Assume test will fail, write code immediately Right: Run test, observe failure, understand why

Over-Mocking

Wrong: Mock every dependency to "isolate" the unit Right: Never mock what you can use for real

Testing Implementation Details

Wrong: Test that internal method X calls internal method Y Right: Test that public interface produces correct results

Verification Checklist

Before marking a step complete:

  • Test was written BEFORE production code
  • Test failed for the correct reason (not syntax/import errors)
  • Implementation is minimal (no extra features)
  • All tests pass (new and existing)
  • Code was refactored while green
  • No untested production code was added

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.