test-driven-development
यह क्या करती है
यह गाइड आपके एजेंट को पहले ऐसा टेस्ट लिखवाती है जो विफल हो, और फिर वह कोड लिखवाती है जो व्यवहार ठीक करे या जोड़े। यह उन डेवलपर्स के लिए है जिन्हें इस बात का प्रमाण चाहिए कि बदलाव काम करता है और बाकी कुछ नहीं तोड़ता।
कब इस्तेमाल करें
- ✓जब आप अपने एजेंट से नया लॉजिक जोड़ने या मौजूदा व्यवहार बदलने को कहें।
- ✓जब कोई बग बताए और आप उसे ठीक करने से पहले टेस्ट से दोहराना चाहें।
- ✓जब आप मौजूदा व्यवहार बिगाड़े बिना किसी एज केस को संभालना जोड़ना चाहें।
Skill का लिंक
https://github.com/cloudflare/computer/blob/main/.agents/skills/test-driven-development/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“एक बग है जिसमें टास्क का शीर्षक खाली सेव हो जाता है। पहले इसके लिए विफल होने वाला टेस्ट लिखिए, फिर उसे ठीक कीजिए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
स्किल एक चक्र का पालन करती है: विफल होने वाला टेस्ट लिखना, फिर उसे पास करने वाला सबसे छोटा कोड लिखना, फिर टेस्ट पास रहते हुए सफ़ाई करना। बग के लिए यह पहले टेस्ट से बग दोहराती है। शुद्ध कॉन्फ़िगरेशन या दस्तावेज़ बदलावों पर यह लागू नहीं होती।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे 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 |
अक्सर पूछे जाने वाले सवाल
क्या यह सिर्फ़ नई सुविधाओं के लिए है?
नहीं। यह बग फ़िक्स और मौजूदा व्यवहार में बदलाव पर भी लागू होती है।
टेस्ट को पहले विफल क्यों होना चाहिए?
जो टेस्ट तुरंत पास हो जाए, वह कुछ साबित नहीं करता, इसलिए स्किल फ़िक्स से पहले उसका विफल होना जाँचती है।
इसे कब छोड़ना चाहिए?
शुद्ध कॉन्फ़िगरेशन बदलाव, दस्तावेज़ अपडेट या ऐसी स्थिर सामग्री के लिए जिसमें व्यवहार नहीं बदलता।
जानकारी
लेखक का मूल विवरण
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
लोकप्रियता
- GitHub स्टार
- 9.8k
- रैंकिंग में स्थान
- #12208
- लाइसेंस
- MIT
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस repository की और skills
cloudflare
9.8kयह आपके एजेंट को काम शुरू करने से पहले Workers, Durable Objects, wrangler और दूसरी सेवाओं के लिए सही Cloudflare प्लेटफ़ॉर्म गाइड की ओर इशारा करती है।
prose
9.8kयह आपके एजेंट को कोड कमेंट, कमिट संदेश, README और दस्तावेज़ों के लिए सादी अंग्रेज़ी में लिखना सिखाती है। जार्गन, संक्षेपों और कॉर्पोरेट भाषा से बचती है।
pull-requests
9.8kयह आपके एजेंट को pull request विवरण लिखना सिखाती है, जो बदलाव की कहानी, उससे ठीक होने वाली समस्या और उसे जाँचने का तरीका बताए।
gardener-tasks
9.8kबताती है कि Gardener टास्क फ़ाइलें कैसे लिखें और जाँचें, जो GitHub Actions से AI रखरखाव काम चलाती हैं, और हर काम क्या बदल सकता है, इस पर सीमाएँ रखती हैं।
मिलती-जुलती skills
test-driven-development
311kयह आपके एजेंट को किसी भी फ़ीचर या सुधार से पहले पहले असफल होने वाला टेस्ट लिखना, उसे असफल होते देखना, फिर पास करने वाला सबसे छोटा कोड लिखना सिखाती है।
verification-before-completion
311kयह आपके एजेंट को किसी काम, सुधार या build के पूरा या पास होने का दावा करने से पहले असली जांच चलाकर उसका आउटपुट पढ़ना सिखाती है।
migrate-to-shoehorn
310kआपकी टेस्ट फ़ाइलों में जोखिम भरे type casts की जगह shoehorn लाइब्रेरी लगाती है, ताकि टेस्ट अधूरे डेटा से भी type checks पास कर सकें।