principle-test-behavior-not-implementation

Distinguish observable user behavior from internal implementation in test assertions.

15.8k|1.6k|Updated Jan 23, 2026
Ready to run
npx skills add https://github.com/cursor/plugins --skill principle-test-behavior-not-implementation-cursor
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: principle-test-behavior-not-implementation
Source: https://github.com/cursor/plugins/tree/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation
Command: npx skills add https://github.com/cursor/plugins --skill principle-test-behavior-not-implementation-cursor

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Tests often fail to catch real bugs because they assert on implementation details rather than what users can observe. When code is refactored, these tests break even though the behavior remains correct, forcing wasteful rewrites. Conversely, some tests pass despite broken behavior because they verify internal structures or expected values derived from the code itself. ## Core Features & Use Cases - Behavior-Focused Assertions: Assert return values, errors, state changes, and external effects—not internal helpers or call sequences. - Refactoring Resilience: Tests survive internal restructuring as long as observable results remain identical. - Bug Detection: Tests fail when actual behavior breaks, catching real defects that matter to users. - Use Case: A payment processing test should verify that an empty cart produces no external call to the payment service, not that an internal helper was skipped. ## Quick Start Review your existing tests and for each one, imagine two edits: breaking the observable behavior and restructuring the internals while keeping results identical—your test should fail on the first and pass on the second.

Frequently Asked Questions about principle-test-behavior-not-implementation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I know if my test is pinned to implementation?▼

Refactor the code while keeping behavior identical—if the test fails, it is pinned to implementation. Common red flags include assertions on internal helper calls, mock verification of private methods, or expected values computed by the code under test rather than derived from requirements.

What counts as observable behavior versus implementation?▼

Behavior includes return values, exceptions, state readable by callers, and external effects like API calls or database rows. Implementation includes private helpers, internal call order, intermediate data, and which internal collaborator performed the work.

When should I assert on exact values versus partial matches?▼

Assert exact values when the contract specifies them: an empty list when no records match, a specific error type when validation fails. Use partial assertions only when the contract allows variability, such as a message the caller never reads.

How do I test behavior when the code calls external services?▼

Mock the external service and assert on the payload it receives, since that is what the service observes. Verify that calls happen or do not happen only when the behavior requires it—mock calls are behavior, mock return values matter only if your code branches on them.

Why should I derive expected values from requirements instead of code runs?▼

Computing expected values from a code run defeats the test's purpose: if the code is wrong, both the code and the expected value are wrong together, so the test passes despite the bug. Always derive expectations from the specification or contract, independent of the implementation.