# Tdd

> Follow Test-Driven Development workflow. Use when the user wants to develop a feature or fix using TDD methodology - write failing tests first, then implement.

- Skill: `foogunlana/tdd` (Agent Skill)
- Install (CLI): `npx skillmds@latest add foogunlana/tdd`
- Raw SKILL.md: https://api.skillmd.com/api/skills/foogunlana/tdd/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Productivity
- Author: foogunlana (https://skillmd.com/u/foogunlana)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/foogunlana/tdd

---


# Test-Driven Development Workflow

Follow the TDD cycle for implementing changes.

## The TDD Cycle

### 1. Write a Failing Test

Create an integration test that describes the expected behavior:

```typescript
describe('Feature Name', () => {
  describe('Success Cases', () => {
    test('should do expected thing', async () => {
      const response = await request(app).get('/api/endpoint')
      expect(response.status).toBe(200)
      expect(response.body).toMatchObject(expectedData)
    })
  })

  describe('Failure Cases', () => {
    test('should fail when invalid input', async () => {
      const response = await request(app).get('/api/endpoint?invalid=true')
      expect(response.status).toBe(400)
    })
  })
})
```

### 2. Verify It Fails

Run the test to confirm it fails for the right reason:
```bash
npm test -- --testPathPattern="test-file-name"
```

### 3. Write Minimum Code to Pass

Implement only what's needed to make the test pass. No more.

### 4. Verify It Passes

Run the test again to confirm it passes.

### 5. Repeat

Continue the cycle for the next piece of functionality.

## Guidelines

- Follow testing guidelines at `.claude/guidelines/testing.md`
- Use Minimum Sufficient Testing (MST) - don't over-test
- Integration tests with real HTTP requests (Jest + Supertest)
- Test success cases and all expected failure scenarios
- Favour editing existing tests over creating new ones
