360 Secure SkillHub
360 安全技能中心

principle-test-behavior-not-implementation

提供测试编写与审查准则:通过“破坏行为”和“只改内部实现”两种假设检验测试,要求断言公开接口的可观察结果,重写或删除仅绑定实现细节的测试。

分类:开发
cursor
热度 38.49
最近更新 2026-11-17 11:40:39

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add cursor/plugins/principle-test-behavior-not-implementation
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
principle-test-behavior-not-implementation
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.
disable-model-invocation
true

Test Behavior, Not Implementation

A test is a claim about what users of the code can observe through its interface: return values, errors, state they can read back, and effects on outside systems. Private helpers, internal call order, and intermediate data are implementation.

Judge each test against two imagined edits:

  • Break the behavior (a wrong value, a skipped or doubled effect). If the test still passes, it proves nothing. The usual causes are a loose assertion, an expected value computed by the code under test, and an assertion on data the test built itself.
  • Change the internals and keep every observable result. If the test fails, it is pinned to the implementation.

Keep a test that catches the first edit and survives the second. Rewrite or delete the rest. Drive the code through its public interface with a concrete input, and derive the expected value from the requirement. What an external service receives is behavior. A call to an internal helper is not. Pair "this never happens" with a case where it does happen. Assert the error type that callers branch on, not the message.