test-driven-development
Fungsinya
Panduan ini membuat agen Anda menulis tes yang gagal sebelum menulis kode yang memperbaiki atau menambah perilaku. Ditujukan untuk pengembang yang menginginkan bukti bahwa sebuah perubahan berfungsi dan tidak merusak bagian lain.
Kapan dipakai
- โSaat Anda meminta agen menambahkan logika baru atau mengubah perilaku yang ada.
- โSaat seseorang melaporkan bug dan Anda ingin bug itu direproduksi dengan tes sebelum diperbaiki.
- โSaat Anda ingin menambahkan penanganan untuk kasus tepi tanpa merusak perilaku saat ini.
Link skill
https://github.com/cloudflare/computer/blob/main/.agents/skills/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
โAda bug di mana judul tugas tersimpan dalam keadaan kosong. Tulis tes yang gagal untuknya dulu, lalu perbaiki.โ
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill mengikuti siklus: tulis tes yang gagal, tulis kode terkecil yang membuatnya lolos, lalu rapikan selagi tes masih lolos. Untuk bug, skill terlebih dahulu mereproduksi bug dengan tes. Skill tidak berlaku untuk perubahan konfigurasi murni atau dokumentasi.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Test-Driven Development
Overview
Write a failing test before writing the code that makes it pass. For bug fixes, reproduce the bug with a test before attempting a fix. Tests are proof โ "seems right" is not done. A codebase with good tests is an AI agent's superpower; a codebase without tests is a liability.
When to Use
- Implementing any new logic or behavior
- Fixing any bug (the Prove-It Pattern)
- Modifying existing functionality
- Adding edge case handling
- Any change that could break existing behavior
When NOT to use: Pure configuration changes, documentation updates, or static content changes that have no behavioral impact.
The TDD Cycle
RED GREEN REFACTOR
Write a test Write minimal code Clean up the
that fails โโโ to make it pass โโโ implementation โโโ (repeat)
โ โ โ
โผ โผ โผ
Test FAILS Test PASSES Tests still PASS
Step 1: RED โ Write a Failing Test
Write the test first. It must fail. A test that passes immediately proves nothing.
// RED: This test fails because createTask doesn't exist yet
describe('TaskService', () => {
it('creates a task with title and default status', async () => {
const task = await taskService.createTask({ title: 'Buy groceries' });
expect(task.id).toBeDefined();
expect(task.title).toBe('Buy groceries');
expect(task.status).toBe('pending');
expect(task.createdAt).toBeInstanceOf(Date);
});
});
Step 2: GREEN โ Make It Pass
Write the minimum code to make the test pass. Don't over-engineer:
// GREEN: Minimal implementation
export async function createTask(input: { title: string }): Promise<Task> {
const task = {
id: generateId(),
title: input.title,
status: 'pending' as const,
createdAt: new Date(),
};
await db.tasks.insert(task);
return task;
}
Step 3: REFACTOR โ Clean Up
With tests green, improve the code without changing behavior:
- Extract shared logic
- Improve naming
- Remove duplication
- Optimize if necessary
Run tests after every refactor step to confirm nothing broke.
The Prove-It Pattern (Bug Fixes)
When a bug is reported, do not start by trying to fix it. Start by writing a test that reproduces it.
Bug report arrives
โ
โผ
Write a test that demonstrates the bug
โ
โผ
Test FAILS (confirming the bug exists)
โ
โผ
Implement the fix
โ
โผ
Test PASSES (proving the fix works)
โ
โผ
Run full test suite (no regressions)
Example:
// Bug: "Completing a task doesn't update the completedAt timestamp"
// Step 1: Write the reproduction test (it should FAIL)
it('sets completedAt when task is completed', async () => {
const task = await taskService.createTask({ title: 'Test' });
const completed = await taskService.completeTask(task.id);
expect(completed.status).toBe('completed');
expect(completed.completedAt).toBeInstanceOf(Date); // This fails โ bug confirmed
});
// Step 2: Fix the bug
export async function completeTask(id: string): Promise<Task> {
return db.tasks.update(id, {
status: 'completed',
completedAt: new Date(), // This was missing
});
}
// Step 3: Test passes โ bug fixed, regression guarded
The Test Pyramid
Invest testing effort according to the pyramid โ most tests should be small and fast, with progressively fewer tests at higher levels:
โฑโฒ
โฑ โฒ E2E Tests (~5%)
โฑ โฒ Full user flows, real browser
โฑโโโโโโโฒ
โฑ โฒ Integration Tests (~15%)
โฑ โฒ Component interactions, API boundaries
โฑโโโโโโโโโโโโโฒ
โฑ โฒ Unit Tests (~80%)
โฑ โฒ Pure logic, isolated, milliseconds each
โฑโโโโโโโโโโโโโโโโโโโฒ
The Beyonce Rule: If you liked it, you should have put a test on it. Infrastructure changes, refactoring, and migrations are not responsible for catching your bugs โ your tests are. If a change breaks your code and you didn't have a test for it, that's on you.
Test Sizes (Resource Model)
Beyond the pyramid levels, classify tests by what resources they consume:
| Size | Constraints | Speed | Example |
|---|---|---|---|
| Small | Single process, no I/O, no network, no database | Milliseconds | Pure function tests, data tra |
Pertanyaan umum
Apakah ini hanya untuk fitur baru?
Tidak. Ini juga berlaku untuk perbaikan bug dan perubahan pada perilaku yang sudah ada.
Mengapa tes harus gagal lebih dulu?
Tes yang langsung lolos tidak membuktikan apa pun, sehingga skill memastikan tes itu gagal sebelum perbaikan.
Kapan saya boleh melewatinya?
Untuk perubahan konfigurasi murni, pembaruan dokumentasi, atau konten statis tanpa perubahan perilaku.
Detail
Deskripsi asli dari pembuat
Drives development with tests. Use when implementing any logic, fixing any bug, or changing any behavior. Use when you need to prove that code works, when a bug report arrives, or when you're about to modify existing functionality.
repo: cloudflare/computer
Popularitas
- Bintang GitHub
- 9.8k
- Peringkat
- #12208
- Lisensi
- MIT
- Diperbarui
- 2/11/2026
Komentar
- โฆ
Skill lain dari repositori ini
cloudflare
9.8kMengarahkan agent Anda ke panduan platform Cloudflare yang tepat untuk Workers, Durable Objects, wrangler, dan layanan lainnya sebelum mulai bekerja.
prose
9.8kMengajari agent Anda menulis bahasa Inggris yang sederhana untuk komentar kode, pesan commit, README, dan dokumentasi. Menghindari jargon, akronim, dan bahasa korporat.
pull-requests
9.8kMengajari agent Anda menulis deskripsi pull request yang jelas dan menceritakan perubahan, masalah yang diperbaiki, dan cara memeriksanya.
gardener-tasks
9.8kMenjelaskan cara menulis dan memeriksa berkas tugas Gardener yang menjalankan pekerjaan pemeliharaan AI dari GitHub Actions, dengan batasan atas apa yang boleh diubah setiap pekerjaan.
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.