agentleFS
smileynetsmileynet/code-spice/skills/code-testing-quality/SKILL.md

code-testing-quality

Skill0 starsChanged 9 months agoMITView on GitHub

Unit testing principles, test structure patterns, test doubles strategy, naming conventions, testing antipatterns, and coverage guidance. Use when writing tests, reviewing test quality, evaluating test coverage, choosing test doubles, fixing flaky tests, or assessing test structure during cook and serve phases. Enhances taster agent during TDD cycle.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    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:

    The failure message test: When a test fails, can you understand the bug from the test name alone?

    line 50

≈ “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

Code Testing Quality

Testing Quality Checklist

  • Each test verifies one behavior (single assertion theme)
  • Tests are independent — no shared mutable state, runs in any order
  • Test names describe the scenario and expected outcome
  • Arrange/Act/Assert sections are visually distinct
  • No logic in tests (no conditionals, loops, or try-catch)
  • Test doubles used only at architectural boundaries
  • Flaky indicators absent (sleeps, real clocks, network calls, file I/O)
  • Edge cases covered (nulls, empty collections, boundaries, error paths)
  • Tests verify behavior, not implementation details
  • Refactoring production code doesn't break tests (unless behavior changes)

Three Properties of Good Tests

PropertyMeaningViolation Signal
IsolatedNo test affects another; runs alone or in any orderTests pass individually but fail together
RepeatableSame result every time, on any machine"Works on my machine," intermittent failures
ClearFailure message pinpoints the problemMust read test code to understand what broke

Test Doubles Decision Table

SituationRecommended DoubleWhy
External API or network callStubIsolation from external non-determinism
Database in integration testFake (in-memory DB)Realistic behavior, fast execution
Verifying a notification was sentMockThe side effect is the behavior
Complex collaborator with stateFakeMaintains realistic internal consistency
Legacy code you can't refactor yetSpyObserve without modifying production code
Internal collaborator (same module)Real objectPrefer real dependencies for internal code

Rule of thumb: Mock at architectural boundaries (network, database, filesystem, external services). Use real objects for internal collaborators.

Test Naming Patterns

PatternExampleBest For
method_scenario_expectedResultwithdraw_insufficientFunds_throwsExceptionUnit tests with clear method focus
should [outcome] when [condition]should reject withdrawal when funds insufficientBehavior-focused tests
given_when_thengivenInsufficientFunds_whenWithdraw_thenThrowsBDD-style tests

The failure message test: When a test fails, can you understand the bug from the test name alone? If yes, the name is good.

Testing Antipatterns

AntipatternSymptomSeverityFix
Flaky testsPass/fail without code changesCriticalRemove non-determinism: no sleeps, no real clocks, no shared state
Test interdependenceTests pass alone, fail togetherCriticalEach test creates/destroys its own data
Testing implementationRefactoring breaks testsMajorAssert on outputs and side effects, not internal method calls
Logic in testsConditionals, loops, try-catch in test codeMajorTests should be straight-line code
Slow testsSuite takes minutes, developers skip itMajorIsolate from I/O; use fakes; parallelize
Obscure testsMust read full test to understand intentModerateDescriptive names, visible AAA structure
Fragile assertionsTests break on irrelevant output changesModerateAssert on relevant fields only
Liar testsTests that always pass regardless of behaviorCriticalVerify tests fail when behavior is wrong (mutation testing)
Giant arrange50 lines of setup, 1 line of actModerateUse builders/factories; consider whether unit is too large
Snapshot abuseBlindly approving snapshot updatesModeratePrefer explicit assertions for logic

Coverage Guidance

Coverage TargetContextRationale
>80% of critical pathsMost projectsBalances thoroughness with diminishing returns
>90%Safety-critical, financialHigher stakes justify investment
60-70%Early-stage, prototypesFocus on core behavior first

Beyond line coverage: Branch coverage is more meaningful. Mutation testing reveals "liar tests" — tests that run code but don't verify it. A high mutation score (>80%) indicates tests that actually catch defects.

"Why Is This Test Bad?"

SymptomLikely AntipatternAction
Test breaks after refactoring (behavior unchanged)Testing implementationAssert on outputs, not method calls
Test fails intermittentlyFlaky testRemove non-determinism (time, state, I/O)
Can't understand failure from test nameObscure testRename to describe scenario + expected outcome
50+ lines of setupGiant arrangeUse builders; consider splitting the unit
Tests pass but bugs shipLiar test / weak assertionsAdd mutation testing
Test suite takes >5 minutesSlow testsReplace I/O with fakes; parallelize

Checklists

Before Writing a Test

  • Identify the specific behavior to verify (not the implementation)
  • Determine test level: unit, integration, or E2E
  • Choose test double strategy (prefer real objects; mock at boundaries)
  • Plan for edge cases and error paths

Test Quality Self-Review

  • Each test has one clear reason to fail
  • Test names describe scenario and expected outcome
  • No shared mutable state between tests
  • No non-determinism (time, randomness, network, filesystem)
  • Assertions verify behavior, not implementation
  • Test fails when the behavior it guards is broken

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.