मुख्य सामग्री पर जाएँ
Skillpedia
टेस्टिंग311k · #95

test-driven-development

यह क्या करती है

यह AI एजेंट को टेस्ट-पहले वाले तरीके से सॉफ़्टवेयर बनाना सिखाती है, जिसमें कोड से पहले उसे कवर करने वाला टेस्ट लिखा जाता है। यह उन डेवलपर्स के लिए है जिन्हें काम करने वाला कोड और हर बदलाव के सही काम करने का सबूत चाहिए।

कब इस्तेमाल करें

  • ✓जब आप कोड में नया फ़ीचर, बग सुधार या व्यवहार में बदलाव मांगें।
  • ✓जब आप टेस्ट मौजूद होने पर कोड को सुरक्षित रूप से रीफ़ैक्टर करना चाहते हों।
  • ✓जब किसी बग को सिर्फ़ उस टेस्ट से सिद्ध करना हो जो बदलाव से पहले विफल हुआ था।

Skill का लिंक

https://github.com/obra/superpowers/blob/main/skills/test-driven-development/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/obra/superpowers/blob/main/skills/test-driven-development/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“एक ऐसा फ़ीचर जोड़िए जिससे उपयोगकर्ता अपनी सूची CSV में निर्यात कर सकें, और पहले टेस्ट लिखिए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

स्किल नए व्यवहार के लिए टेस्ट लिखती है, उसे चलाकर पुष्टि करती है कि वह विफल होता है, फिर उसे पास करने के लिए सबसे कम कोड लिखती है। इसके बाद टेस्ट हरे रखते हुए कोड को साफ़ करती है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे 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 your human partner):

  • 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

digraph tdd_cycle {
    rankdir=LR;
    red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
    verify_red [label="Verify fails\ncorrectly", shape=diamond];
    green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
    verify_green [label="Verify passes\nAll green", shape=diamond];
    refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
    next [label="Next", shape=ellipse];

    red -> verify_red;
    verify_red -> green [label="yes"];
    verify_red -> red [label="wrong\nfailure"];
    green -> verify_green;
    verify_green -> refactor [label="yes"];
    verify_green -> green [label="no"];
    refactor -> verify_green [label="stay\ngreen"];
    verify_green -> next;
    next -> red;
}

RED - Write Failing Test

Write one minimal test showing what should happen.

<Good> ```typescript test('retries failed operations 3 times', async () => { let attempts = 0; const operation = () => { attempts++; if (attempts < 3) throw new Error('fail'); return 'success'; };

const result = await retryOperation(operation);

expect(result).toBe('success'); expect(attempts).toBe(3); });

Clear name, tests real behavior, one thing
</Good>

<Bad>
```typescript
test('retry works', async () => {
  const mock = jest.fn()
    .mockRejectedValueOnce(new Error())
    .mockRejectedValueOnce(new Error())
    .mockResolvedValueOnce('success');
  await retryOperation(mock);
  expect(mock).toHaveBeenCalledTimes(3);
});

Vague name, tests mock not code </Bad>

Requirements:

  • One behavior
  • Clear name
  • Real code (no mocks unless unavoidable)

Verify RED - Watch It Fail

MANDATORY. Never skip.

npm test path/to/test.test.ts

Confirm:

  • Test fails (not errors)
  • Failure message is expected
  • Fails because feature missing (not typos)

Test passes? You're testing existing behavior. Fix test.

Test errors? Fix error, re-run until it fails correctly.

GREEN - Minimal Code

Write simplest code to pass the test.

<Good> ```typescript async function retryOperation<T>(fn: () => Promise<T>): Promise<T> { for (let i = 0; i < 3; i++) { try { return await fn(); } catch (e) { if (i === 2) throw e; } } throw new Error('unreachable'); } ``` Just enough to pass </Good> <Bad> ```typescript async function retryOperation<T>( fn: () => Promise<T>, options?: { maxRetries?: number; backoff?: 'linear' | 'exponential'; onRetry?: (attempt: number) => void; } ): Promise<T> { // YAGNI } ``` Over-engineered </Bad>

Don't add features, refactor other code, or "improve" beyond the test.

Verify GREEN - Watch It Pass

MANDATORY.

npm test path/to/test.test.ts

Confirm:

  • Test passes
  • Other tests still pass
  • Output pristine (no errors, warnings)

Test fails? Fix code, not test.

Other tests fail? Fix now.

"Other tests" means the project's suite, not just your file. A green run of the test you wrote is not a green suite. Before you call the change done, run the project's test command (bare pytest, npm test, cargo test — whatever the repo uses) even when your task named only one test file. A scope statement in your task bounds the deliverable, not your verification. Any failure that run shows — including one you didn't cause — goes in your report by name; a red test you watched scroll past and didn't mention is a report falsified by omission.

REFACTOR - Clean Up

After green only:

  • Remove duplication
  • Improve names
  • Extract helpers

Keep tests green. Don't add be

अक्सर पूछे जाने वाले सवाल

क्या तेज़ प्रोटोटाइप के लिए टेस्ट छोड़े जा सकते हैं?

फेंक दिए जाने वाले प्रोटोटाइप और जेनरेट किए गए कोड अपवाद हैं, लेकिन टेस्ट छोड़ने से पहले स्किल आपसे पूछती है।

अगर कोड उसके टेस्ट से पहले लिखा जा चुका हो तो?

स्किल कहती है कि ऐसा कोड हटाकर टेस्ट से दोबारा लिखा जाए, ताकि डिज़ाइन सच में टेस्ट से तय हो।

टेस्ट को असफल होते क्यों देखें?

जो टेस्ट कभी असफल होते नहीं देखा गया, वह शायद सही चीज़ नहीं जांच रहा हो।

जानकारी

लेखक का मूल विवरण

Use when implementing any feature or bugfix, before writing implementation code

repo: obra/superpowers

लोकप्रियता

GitHub स्टार
311k
रैंकिंग में स्थान
#95
लाइसेंस
MIT
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

brainstorming

311k

यह आपके एजेंट को केंद्रित सवाल पूछकर और साफ़ विकल्प रखकर, कुछ भी नया बनाने से पहले यह समझने में मदद करती है कि आप असल में क्या चाहते हैं।

प्रोडक्टिविटीटास्क और प्रोजेक्ट

executing-plans

311k

यह आपके एजेंट को मौजूदा सेशन में लिखी इम्प्लीमेंटेशन योजना को चरण-दर-चरण पूरा करने में मदद करती है, हर चरण के बाद अगला शुरू करने से पहले उसकी जांच करके।

कोडिंगसामान्य कोडिंग

finishing-a-development-branch

311k

यह आपके एजेंट को तैयार कोड को टेस्ट चलाकर समेटने में मदद करती है, फिर merge करने, pull request खोलने या branch रखने के साफ़ विकल्प देती है।

कोडिंगसामान्य कोडिंग

receiving-code-review

311k

यह आपके एजेंट को कोड समीक्षा की टिप्पणियों को ध्यान से परखने में मदद करती है, कुछ भी बदलने से पहले हर बिंदु को कोड से मिलाकर।

कोडिंगसामान्य कोडिंग

मिलती-जुलती skills