TDD Workflow Skill
Purpose
Enforce test-driven development: RED → GREEN → REFACTOR.
Activation
- User says "let's do TDD" or "write tests first"
- Starting a new feature
- Fixing a bug (write test that reproduces it)
Workflow
RED — Write Failing Test
- Understand the requirement
- Write a test that describes expected behavior
- Run the test — it MUST fail
- If it passes, the test is wrong — fix the test
GREEN — Make It Pass
- Write the MINIMUM code to make the test pass
- Run the test — it MUST pass
- Do NOT write extra code yet
REFACTOR — Improve
- Clean up the code
- Run tests again — they MUST still pass
- Repeat until satisfied
Example
// RED: Write a failing test first
describe('UserService', () => {
it('should hash passwords on create', async () => {
const user = await createUser({ password: 'secret123' })
expect(user.passwordHash).not.toBe('secret123')
expect(user.passwordHash).toMatch(/^\$2[abyb]\$.{56}$/) // bcrypt
})
})
// GREEN: Write minimal implementation
async function createUser(data: { password: string }) {
const passwordHash = await bcrypt.hash(data.password, 12)
return db.user.create({ ...data, passwordHash })
}
Integration
- Use build-check after implementation
- Use test-coverage to verify coverage
- Log lessons if TDD revealed a gotcha
Anti-Patterns
- Do NOT skip the RED phase — verify the test fails first
- Do NOT write more code than needed to pass the test
- Do NOT refactor while tests are failing
- Do NOT write tests after implementation (that's verification, not TDD)