principle-test-behavior-not-implementation
できること
このスキルは、良いテストを書き、維持するための規則を、アシスタントに与えます。リファクタリングのたびに壊れるテスト、またはコードが間違っているのに通ってしまうテストに悩む開発者向けです。
使う場面
- ✓テストを書く、変更する、または残すとき。
- ✓動作が変わっていないのに、リファクタリングのたびにテストが失敗するとき。
- ✓わざと動作を壊したのに、テストがまだ通ってしまうとき。
スキルのリンク
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“リファクタリングのたびにテストが壊れますが、利用者に見える変更はありませんでした。動作を確認するように書き直してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
アシスタントは、各テストを2つの想定される変更に照らして確認します。動作を壊す変更は、テストが捕まえなければなりません。内部だけを変える変更は、テストが生き残らなければなりません。どちらかに失敗するテストは書き直すか削除し、公開のインターフェースを通してコードを動かします。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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 contract decides, not the shape of the assertion. When "an empty cart never charges" is the promise, an assertion that the payment client got no call is behavior. Pair it with a case where the charge happens, so that the test shows it can see a call. The payload that a mocked external service receives is behavior, because that service observes it. A call to an internal helper is implementation, because no user can see it. An empty list is the exact answer when no record matches, and a hollow check when the test only needs some result. An exact error message pins wording that no caller reads. The error type that callers branch on is the contract.
A test can pin an invariant instead of a call, such as a key that must exist in two tables or a compile-time type check. The invariant is the behavior.
よくある質問
動作とは何ですか?
コードの利用者が観察できるもの、例えば戻り値、エラー、読み取れる状態、送られたメッセージのような効果などです。
弱いテストとは?
期待値がテスト対象のコード自身によって計算されるもの、または契約よりも緩いアサーションを持つものです。
テストは非公開のヘルパーを確認すべきですか?
いいえ。非公開のヘルパーや内部の呼び出し順序は、動作ではなく実装の詳細です。
詳細
作者による元の説明
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.
repo: cursor/plugins
人気
- GitHubのスター
- 15k
- ランキング
- #10990
- ライセンス
- —
- 更新日
- 2026/10/31
コメント
- …
このリポジトリの他のスキル
advisor
15k重要な判断の前や、エラーで行き詰まったときなど、要所でより強力な第二のモデルに相談させます。機能をオンにしている場合のみ動きます。
check-agent-compatibility
15kAIコーディングエージェントがリポジトリを起動し、検証し、文書化できるかを包括的に確認し、主な問題とともに1つの互換性スコアを返します。
cli-for-agents
15kAIエージェントがプロンプトなしで実行でき、わかりやすいヘルプ文と例を備えるように、コマンドラインツールを設計または確認する方法をエージェントに教えます。
continual-learning
15k過去のチャットを確認する作業を専用のメモリ更新エージェントに任せることで、AGENTS.mdのメモを最新に保ちます。
似ているスキル
test-driven-development
311k機能や修正を作る前に、まず失敗するテストを書き、それが失敗するのを確認してから、合格させる最小のコードを書くようエージェントに教えます。
verification-before-completion
311kタスク、修正、ビルドが完了した、または合格したと主張する前に、実際のチェックを実行し、その出力を読むようエージェントに教えます。
migrate-to-shoehorn
310kテストファイル内の危険な型キャストを、shoehornライブラリに置き換え、テストが部分的なデータを使いつつ型チェックを通るようにします。