test-driven-developmentlisted
Install: claude install-skill grimaldost/craft-collection
# Test-Driven Development
Write the test first and watch it fail. A test you never saw fail proves
nothing — it can pass for reasons unrelated to the behavior it was meant to
pin.
This is a **rigid** skill. The bright line: **production code is written only
against a test you have watched fail.** It holds for features, bug fixes,
refactors, and behavior changes alike. Exceptions — throwaway prototypes,
generated code, pure configuration — are agreed with the user before skipping
the cycle, not self-granted.
## The cycle
One behavior at a time: red, verify red, green, verify green, refactor.
### 1. Red — write one failing test
One behavior, a name that describes it, real code over mocks.
```typescript
// Good: clear name, real behavior, one thing
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);
});
```
A vague name ("retry works") asserting against a mock tests the mock, not the
code.
### 2. Verify red — watch it fail
Run the test. Confirm three things: it fails rather than errors, the failure
message is the one you expected, and it fails because the feature is missing
— not because of a typo. A test that passes here is testing behavior that
already exists; fix the test. A test that errors is not failing correctly;