# Tdd Process

> Enforces Red-Green-Refactor with hard gates: Red phase writes failing test that MUST fail on assertion (not syntax/config) and presents test+failure before proceeding, runs tests on the specific file (not full suite) after each phase, Green phase writes minimal code to pass and stops there, Refactor phase runs test after each micro-change and MUST stay Green throughout. Generates failing test cases, validates test failure before proceeding, gates implementation behind passing red-phase checks. Use when the user requests TDD workflow, asks to write tests first, mentions Red-Green-Refactor methodology, or uses trigger words: TDD, test-first, test gate.

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

---

# TDD Process

## Process Steps

### Step 1: Red Phase
- Write a failing test for the target behavior
- Run the test suite on that specific file
- **Gate:** Failure must be on the assertion — not a syntax or configuration error
- **Checkpoint:** Present the test code and failure output before proceeding to implementation

### Step 2: Green Phase
- Write the minimal code required to pass the test — nothing more
- Run the test file
- **Checkpoint:** Present the minimal implementation once tests pass

### Step 3: Refactor Phase
- Clean up duplication, naming, class structures, and documentation
- Run the test suite after each micro-change
- **Gate:** Tests must remain green throughout

---

## Framework Example

### RSpec
**Failing Test (RED):**
```ruby
# spec/user_spec.rb
RSpec.describe User do
  describe "#full_name" do
    it "combines first name and last name" do
      user = User.new(first_name: "Ada", last_name: "Lovelace")
      expect(user.full_name).to eq("Ada Lovelace")
    end
  end
end
```
*Failure command & output:*
```bash
$ bundle exec rspec spec/user_spec.rb
...
1 example, 1 failure
Failed examples:
rspec ./spec/user_spec.rb:4 # User#full_name combines first name and last name (NoMethodError: undefined method `full_name')
```

**Minimal Implementation (GREEN):**
```ruby
# lib/user.rb
class User
  def initialize(first_name:, last_name:)
    @first_name, @last_name = first_name, last_name
  end

  def full_name
    "#{@first_name} #{@last_name}"
  end
end
```

> Additional framework examples are available in companion files:
> - `EXAMPLES_PYTEST.md` — pytest (Python)
> - `EXAMPLES_JEST.md` — Jest (JavaScript/TypeScript)
> - `EXAMPLES_GO_TEST.md` — Go testing package

---

## Integration

| Context | Next Skill |
|---------|-----------|
| Testing first slices | **test-planning-process** |
| Refactoring green code | **refactor-process** |
| Documenting public APIs | **write-yard-docs** |

