Zum Inhalt springen
Skillpedia
Tests15k · #10990

principle-test-behavior-not-implementation

Was er macht

Gibt dem Assistenten eine Regel, gute Tests zu schreiben und zu pflegen. Er ist für Entwickler gedacht, deren Tests bei jedem Refactoring brechen oder bestehen, obwohl der Code falsch ist.

Wann du ihn nutzt

  • ✓Wenn du einen Test schreibst, änderst oder behältst.
  • ✓Wenn Tests bei jedem Refactoring fehlschlagen, obwohl sich das Verhalten nicht geändert hat.
  • ✓Wenn ein Test nach einer bewusst herbeigeführten Verhaltensänderung noch besteht.

Link zum Skill

https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.md

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Unsere Tests brechen bei jedem Refactoring, selbst wenn sich nichts für Nutzer geändert hat. Schreib sie um, sodass sie das Verhalten prüfen.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Der Assistent prüft jeden Test anhand zweier gedachter Änderungen: einer, die das Verhalten bricht und die der Test fangen muss, und einer, die nur Interna ändert und die er überstehen muss. Tests, die eine der beiden Prüfungen nicht bestehen, schreibt er um oder löscht sie und steuert den Code dabei über seine öffentliche Schnittstelle.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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.

Häufige Fragen

Was zählt als Verhalten?

Was Nutzer des Codes beobachten können, etwa Rückgabewerte, Fehler, lesbarer Zustand und Wirkungen wie eine gesendete Nachricht.

Was ist ein schwacher Test?

Einer, dessen erwarteter Wert vom getesteten Code selbst berechnet wird, oder dessen Prüfung lockerer ist als der Vertrag.

Sollen Tests private Hilfsfunktionen prüfen?

Nein. Private Hilfsfunktionen und die interne Aufrufreihenfolge sind Implementierungsdetails, kein Verhalten.

Details

Originalbeschreibung des Autors

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

Beliebtheit

GitHub-Sterne
15k
Platz im Ranking
#10990
Lizenz
—
Aktualisiert
31.10.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills