test-driven-developmentlisted
Install: claude install-skill izyanrajwani/agent-skills-library
# Test-Driven Development
Write test first. Watch it fail. Write minimal code to pass. Refactor.
**Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
## The Iron Law
```
NO BEHAVIOR-CHANGING PRODUCTION CODE WITHOUT A FAILING TEST FIRST
```
Wrote code before test? Delete it completely. Implement fresh from tests.
**Refactoring is exempt:** The refactor step changes structure, not behavior. Tests stay green throughout. No new failing test required.
## Red-Green-Refactor Cycle
```
RED ──► Verify Fail ──► GREEN ──► Verify Pass ──► REFACTOR ──► Verify Pass ──► Next RED
│ │ │
▼ ▼ ▼
Wrong failure? Still failing? Broke tests?
Fix test, retry Fix code, retry Fix, retry
```
### RED - Write Failing Test
Write one minimal test for one behavior.
**Good example:**
```typescript
test('retries failed operations 3 times', async () => {
let attempts = 0;
const operation = async () => {
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, asserts observable outcome*
**Bad example:**
```typescript
test('retry works', async () => {
const mock = jest.fn()
.mockRejected