# Principle Test Behavior Not Implementation

Apply when you write, change, or keep a test.

- Repository: https://github.com/michael-denyer/pstack-claude (3725 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add michael-denyer/pstack-claude --skill principle-test-behavior-not-implementation -g -a claude-code -y`
Codex: `npx skills add michael-denyer/pstack-claude --skill principle-test-behavior-not-implementation -g -a codex -y`
Cursor: `npx skills add michael-denyer/pstack-claude --skill principle-test-behavior-not-implementation -g -a cursor -y`
Gemini CLI: `npx skills add michael-denyer/pstack-claude --skill principle-test-behavior-not-implementation -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add michael-denyer/pstack-claude`

## Description

Apply when you write, change, or keep a test. Assert what the code's users can observe, so that the test fails when that behavior breaks and keeps passing when only the internals change.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Test Behavior, Not Implementation

A test is a claim about what the code does for its users: a caller, an end user, or another service. Behavior is what those users can observe through the interface they use. That includes return values, errors, state they can read back, and effects on systems outside the code, such as a request sent, a row written, or a message emitted. Implementation is what they cannot observe: private helpers, internal call order, intermediate data, and which internal collaborator did the work.

Judge each test against two imagined edits:

- **Break the behavior.** Make the code return a wrong value, skip an effect, or do the effect twice. If the test still passes, it proves nothing. The usual causes are an assertion looser than the contract, an expected value computed by the code under test, a restated constant or prompt string that never runs the code that reads it, and an assertion on data that the test built itself.
- **Change the internals.** Keep every observable result the same and restructure the code underneath. If the test now fails, it is pinned to the implementation. It will need a rewrite on every refactor and still catches no bug.

Keep a test that catches the first edit and survives the second. Rewrite or delete the rest. To write a test that does both, drive the code through its users' interface with a concrete input. Derive the expected value from the requirement, not from a run of the code. Assert what the contract promises, no less and no more.

The rest: https://github.com/michael-denyer/pstack-claude/blob/HEAD/plugins/pstack/skills/principle-test-behavior-not-implementation/SKILL.md
