agentleFS
MorganOnGitHubMorganOnGitHub/tackle/skills/testing-first/SKILL.md

testing-first

Skill0 starsChanged 45 days agoMITView on GitHub

Use when about to implement or change behavior in code that has, or should have, automated tests, including bug fixes

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    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:

    Code without a test harness: add a harness if it's cheap and the user agrees.

    line 13
  2. Distinctive:

    Green: Write the simplest code that passes.

    line 20
  3. Distinctive:

    Don't delete working code.

    line 31
  4. Distinctive:

    Every new behavior has a test you saw fail for the expected reason and then pass, and the relevant suite is green.

    line 40

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Testing First

A test you have watched fail is proof it checks something real. A test written after the code and passing on its first run proves much less: it may test the wrong thing, or nothing. Writing the test first also makes you decide what the code should do before deciding how.

Scale it

  • Behavior changes and bug fixes in tested code: red → green → refactor, below.
  • Code without a test harness: add a harness if it's cheap and the user agrees. Otherwise use the best available evidence (a script, a manual run with captured output) and say that's what you did.
  • Config, generated code, layout/styling, throwaway spikes: tests are optional. Verify another way.

How

  1. Red. Write one small test for the next behavior, named for that behavior. Edge cases and error paths each get a test of their own. Use real code; mock only at boundaries you can't control (network, clock, third-party services). Assert on what the code does, not on what the mock received, and don't add methods to production code just for tests.
  2. Watch it fail, and for the right reason. "Function not defined" or "expected X, got Y" is right; a typo or import error is not. If it passes straight away, it isn't testing the new behavior, so change the test.
  3. Green. Write the simplest code that passes. Don't add options or features the test doesn't ask for.
  4. Run the relevant suite. New and existing tests pass, with no new warnings.
  5. Refactor with the tests green: tidy names, remove duplication. Behavior stays the same.
  6. Repeat for the next behavior.

For bug fixes, the first test reproduces the bug. That test is the regression guard.

A test that's hard to write is feedback on the design. Heavy setup or mocks everywhere usually mean the code is too coupled, so simplify the interface or pass dependencies in.

Wrote the code first?

Don't delete working code. Write the test now, then prove it can fail: temporarily revert or break the code under test, confirm the test fails, and restore it. If it doesn't fail, the test is too weak; strengthen it.

Skip or shorten when

  • The user says not to test or to test later. Mention the risk once, then follow their call.
  • You're spiking to learn something. Throw the spike away or backfill tests before relying on it.

Done means

Every new behavior has a test you saw fail for the expected reason and then pass, and the relevant suite is green.

Next

  • verifying-before-claiming
  • debugging-systematically if a test fails in a way you don't understand

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.