test-driven-development
Fungsinya
Skill ini membuat AI Anda menulis tes sebelum kode untuk fitur baru, perbaikan bug, dan perubahan perilaku. Skill ini ditujukan untuk pengembang yang menginginkan kode yang tercakup tes sejak awal.
Kapan dipakai
- āSaat Anda meminta AI menambahkan fitur baru atau mengubah cara kode berperilaku.
- āSaat Anda meminta AI memperbaiki bug dan menginginkan tes yang membuktikan perbaikannya.
- āSaat Anda ingin merefaktor kode dengan aman dengan tes yang sudah ada.
Link skill
https://github.com/NousResearch/hermes-agent/blob/main/skills/software-development/test-driven-development/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
āTambahkan fitur retry ke fungsi unggah kami, dan tulis tesnya terlebih dahulu agar kita tahu fitur itu bekerja.ā
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill mengikuti siklus merah-hijau-refaktor: tulis satu tes kecil dan lihat tes itu gagal, tulis kode paling sedikit untuk membuatnya lolos, lalu bersihkan. AI menghapus kode apa pun yang ditulisnya sebelum tes yang gagal.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Test-Driven Development (TDD)
Overview
Write the test first. Watch it fail. Write minimal code to pass.
Core principle: If you didn't watch the test fail, you don't know if it tests the right thing.
Violating the letter of the rules is violating the spirit of the rules.
When to Use
Always:
- New features
- Bug fixes
- Refactoring
- Behavior changes
Exceptions (ask the user first):
- Throwaway prototypes
- Generated code
- Configuration files
Thinking "skip TDD just this once"? Stop. That's rationalization.
The Iron Law
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Write code before the test? Delete it. Start over.
No exceptions:
- Don't keep it as "reference"
- Don't "adapt" it while writing tests
- Don't look at it
- Delete means delete
Implement fresh from tests. Period.
Red-Green-Refactor Cycle
RED ā Write Failing Test
Write one minimal test showing what should happen.
Good test:
def test_retries_failed_operations_3_times():
attempts = 0
def operation():
nonlocal attempts
attempts += 1
if attempts < 3:
raise Exception('fail')
return 'success'
result = retry_operation(operation)
assert result == 'success'
assert attempts == 3
Clear name, tests real behavior, one thing.
Bad test:
def test_retry_works():
mock = MagicMock()
mock.side_effect = [Exception(), Exception(), 'success']
result = retry_operation(mock)
assert result == 'success' # What about retry count? Timing?
Vague name, tests mock not real code.
Requirements:
- One behavior per test
- Clear descriptive name ("and" in name? Split it)
- Real code, not mocks (unless truly unavoidable)
- Name describes behavior, not implementation
Verify RED ā Watch It Fail
MANDATORY. Never skip.
# Use terminal tool to run the specific test
pytest tests/test_feature.py::test_specific_behavior -v
Confirm:
- Test fails (not errors from typos)
- Failure message is expected
- Fails because the feature is missing
Test passes immediately? You're testing existing behavior. Fix the test.
Test errors? Fix the error, re-run until it fails correctly.
GREEN ā Minimal Code
Write the simplest code to pass the test. Nothing more.
Good:
def add(a, b):
return a + b # Nothing extra
Bad:
def add(a, b):
result = a + b
logging.info(f"Adding {a} + {b} = {result}") # Extra!
return result
Don't add features, refactor other code, or "improve" beyond the test.
Cheating is OK in GREEN:
- Hardcode return values
- Copy-paste
- Duplicate code
- Skip edge cases
We'll fix it in REFACTOR.
Verify GREEN ā Watch It Pass
MANDATORY.
# Run the specific test
pytest tests/test_feature.py::test_specific_behavior -v
# Then run ALL tests to check for regressions
pytest tests/ -q
Confirm:
- Test passes
- Other tests still pass
- Output pristine (no errors, warnings)
Test fails? Fix the code, not the test.
Other tests fail? Fix regressions now.
REFACTOR ā Clean Up
After green only:
- Remove duplication
- Improve names
- Extract helpers
- Simplify expressions
Keep tests green throughout. Don't add behavior.
If tests fail during refactor: Undo immediately. Take smaller steps.
Repeat
Next failing test for next behavior. One cycle at a time.
Avoid Horizontal Slices
Do not write all tests first and then all implementation. That is horizontal slicing: RED becomes "write a pile of imagined tests" and GREEN becomes "make the pile pass." It produces brittle tests because the tests are designed before the implementation has taught you what behavior and interface actually matter.
Use vertical tracer bullets instead:
WRONG:
RED: test1, test2, test3, test4
GREEN: impl1, impl2, impl3, impl4
RIGHT:
REDāGREEN: test1āimpl1
REDāGREEN: test2āimpl2
REDāGREEN: test3āimpl3
A tracer bullet is one end-to-end behavior slice. It proves the path works, teaches you about the interface, and keeps each next test grounded in what you just learned.
Why Order Matters
"I'll write tests after to verify it works"
Tests written after code pass immediately. Passing immediately proves nothing:
- Might test the wrong thing
- Might test implementation, not behavior
- Might miss edge cases you forgot
- You never saw it catch the bug
Test-first forces you to see the test fail,
Pertanyaan umum
Apakah ada pengecualian?
Ya. Skill menyatakan tanyakan dulu untuk prototipe sekali pakai, kode yang dihasilkan, dan file konfigurasi.
Mengapa tes harus gagal lebih dulu?
Skill menyatakan jika Anda tidak melihat tes itu gagal, Anda tidak tahu apakah tes itu menguji hal yang benar.
Bagaimana jika saya sudah menulis kodenya?
Skill menyatakan hapus kode itu dan mulai ulang dari tes.
Detail
Deskripsi asli dari pembuat
TDD: enforce RED-GREEN-REFACTOR, tests before code.
Popularitas
- Bintang GitHub
- 260k
- Peringkat
- #626
- Lisensi
- MIT
- Diperbarui
- 2/11/2026
Komentar
- ā¦
Skill lain dari repositori ini
agent-merge-conflict-arbiter
260kMenyelesaikan konflik merge git antara cabang dua agent sebagai pihak ketiga yang netral, menghasilkan satu hasil gabungan untuk repo.
antigravity-cli
260kMemandu Anda memasang, memperbarui, dan memecahkan masalah alat baris perintah Antigravity, termasuk plugin, login, dan sandbox-nya.
blackbox
260kMemungkinkan agent Anda menyerahkan tugas pemrograman ke alat baris perintah Blackbox AI, yang menjalankan beberapa model AI dan memilih hasil terbaik.
dynamic-workflow
260kMengajari agent Anda menjalankan pekerjaan sejenis dalam jumlah besar sebagai skrip tersimpan, sehingga hanya hasil terverifikasi yang kembali ke percakapan utama.
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.