← ClaudeAtlas

test-driven-developmentlisted

Use when implementing any feature, bugfix, or behavior change — before writing implementation code. Trigger on: "add a feature", "fix this bug", "implement", "build this function", "refactor", "add retry logic", "handle errors", or any request to write production code. Also trigger when the user describes desired behavior that implies new code ("it should retry 3 times", "validate the email", "parse the CSV and output JSON"). The key signal is: code needs to be written, and tests should come first.
petermcalister/shared-skills · ★ 2 · Data & Documents · score 68
Install: claude install-skill petermcalister/shared-skills
# Test-Driven Development (TDD) 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. A test that passes immediately proves nothing — it might test the wrong behavior, test the implementation instead of the requirement, or miss edge cases entirely. ## When to Use **Always:** new features, bug fixes, refactoring, behavior changes. **Exceptions (ask the user):** throwaway prototypes, generated code, configuration. ## The Cycle ``` RED → write one failing test ↓ Verify it fails for the right reason (feature missing, not typo) ↓ GREEN → write simplest code to pass ↓ Verify all tests pass, output clean ↓ REFACTOR → clean up while staying green ↓ Repeat for next behavior ``` ### RED — Write Failing Test One minimal test showing what should happen. Clear name, real behavior, one thing. ```typescript // Good: clear name, tests real behavior 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); }); // Bad: vague name, tests mock not code test('retry works', async () => { const mock = jest.fn().mockRejectedValueOnce(new Error()).mockResolvedValueOnce('ok'); await retryOperation(mock); expect(mock).toHave