agentleFS
jtarorehjtaroreh/agystack/skills/principle-test-behavior-not-implementation/SKILL.md

principle-test-behavior-not-implementation

Skill58 starsChanged 3 months agoMITView on GitHub

Apply when writing or reviewing tests. Test what the system does from the outside (inputs, outputs, observable behavior, invariants), not how it is structured internally (private methods, call counts, internal state).

10 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use benchmark-checklist, principle-explain-the-number and 1 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.
  • creedantsSkill

    benchmark-checklist

    Vet a perf measurement (limiter, tuning, limits, errors, repeatability, relevance, and whether the work happened) before you report or act on it. Use when you run a benchmark or report a speedup or regression you measured.

    Also in 4 projects that use this

  • creedantsSkill

    principle-explain-the-number

    Apply before you trust, report, or act on a number you measured: a speedup, a regression, a throughput, a latency, or an eval result. Find what limits it, and rule out that it measured something other than the work you think.

    Also in 4 projects that use this

  • lobomfzSkill

    correct

    Correct-option selection. Use when the user says /correct or asks what is most correct.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 7

    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 against observable behavior and contracts, not internal implementation details.

    line 9
  2. Distinctive:

    Pattern: Ask: "If I rewrote the internals completely, would this test still pass?"

    line 13
  3. Distinctive:

    Treat the unit or subsystem as a black box with defined inputs and outputs.

    line 16
  4. Distinctive:

    Test contracts, invariants, and edge cases.

    line 17
  5. Distinctive:

    Use public APIs and observable side effects.

    line 18
  6. Distinctive:

    Verify state through public query methods or final output artifacts.

    line 19
  7. Distinctive:

    If changing internal implementation breaks tests while the feature still works, the tests were testing implementation, not behavior.

    line 28

“Common” is measured: kept by at least 6 in 10 of the 10 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 Behavior, Not Implementation

Write tests against observable behavior and contracts, not internal implementation details. Tests should survive refactoring without changes.

Why: Tests coupled to internal details (mocking internal methods, asserting specific call counts, inspecting private state) break when code is refactored, even when behavior is unchanged. This creates test maintenance burden and discourages refactoring.

Pattern: Ask: "If I rewrote the internals completely, would this test still pass?"

Good tests:

  • Treat the unit or subsystem as a black box with defined inputs and outputs.
  • Test contracts, invariants, and edge cases.
  • Use public APIs and observable side effects.
  • Verify state through public query methods or final output artifacts.

Avoid:

  • Mocking functions you own (prefer real instances or lightweight fakes).
  • Asserting on internal call counts or execution order when order is not part of the contract.
  • Asserting on exact internal data structures rather than the public result.
  • Writing tests that duplicate the implementation logic.

Refactoring test:

  • If changing internal implementation breaks tests while the feature still works, the tests were testing implementation, not behavior.
  • Rewrite the brittle tests to assert on public outcomes before proceeding with the refactor.

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.