principle-test-behavior-not-implementation
Fungsinya
Memberi asisten aturan untuk menulis dan memelihara tes yang baik. Cocok untuk pengembang yang tesnya rusak setiap kali refactor atau masih lulus padahal kodenya salah.
Kapan dipakai
- βSaat Anda menulis, mengubah, atau memelihara sebuah tes.
- βSaat tes gagal setiap kali refactor walaupun perilakunya tidak berubah.
- βSaat sebuah tes masih lulus setelah Anda sengaja merusak perilakunya.
Link skill
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-test-behavior-not-implementation/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTes kami rusak setiap kali kita refactor, padahal tidak ada yang terlihat oleh pengguna berubah. Tulis ulang agar memeriksa perilaku.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Asisten memeriksa setiap tes terhadap dua suntingan imajiner: satu yang merusak perilaku, yang harus ditangkap tes, dan satu yang hanya mengubah internal, yang harus dilewati tes. Ia menulis ulang atau menghapus tes yang gagal dalam salah satu pemeriksaan, dengan menggerakkan kode melalui antarmuka publiknya.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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.
Pertanyaan umum
Apa yang dihitung sebagai perilaku?
Apa yang bisa diamati pengguna kode, seperti nilai kembalian, error, state yang bisa dibaca, dan efek seperti pesan yang terkirim.
Apa tes yang lemah?
Tes yang nilai yang diharapkannya dihitung oleh kode yang diuji, atau asersinya lebih longgar daripada kontraknya.
Haruskah tes memeriksa helper privat?
Tidak. Helper privat dan urutan panggilan internal adalah detail implementasi, bukan perilaku.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 15k
- Peringkat
- #10990
- Lisensi
- β
- Diperbarui
- 31/10/2026
Komentar
- β¦
Skill lain dari repositori ini
advisor
15kMemungkinkan agent Anda berkonsultasi dengan model kedua yang lebih kuat pada titik pemeriksaan penting, seperti sebelum keputusan besar atau saat terhenti pada error, jika Anda mengaktifkannya.
check-agent-compatibility
15kMenjalankan pemeriksaan menyeluruh tentang apakah agent pengodean AI bisa memulai, memverifikasi, dan mendokumentasikan repositori, lalu mengembalikan satu skor kompatibilitas dengan masalah utamanya.
cli-for-agents
15kMengajarkan agent Anda merancang atau meninjau alat baris perintah agar agent AI bisa menjalankannya tanpa prompt, dengan teks bantuan dan contoh yang jelas.
continual-learning
15kMenjaga catatan AGENTS.md Anda tetap mutakhir dengan menyerahkan pekerjaan meninjau chat sebelumnya kepada pembaru memori khusus.
Skill serupa
test-driven-development
311kMengajari agent Anda menulis tes yang gagal dulu, melihatnya gagal, lalu menulis kode terkecil yang lulus, sebelum membangun fitur atau perbaikan apa pun.
verification-before-completion
311kMengajari agent Anda menjalankan pemeriksaan nyata dan membaca keluarannya sebelum menyatakan tugas, perbaikan, atau build sudah selesai atau lulus.
migrate-to-shoehorn
310kMengganti type cast berisiko di file tes Anda dengan pustaka shoehorn, sehingga tes bisa memakai data parsial dan tetap lulus pemeriksaan tipe.