test-driven-developmentlisted
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