Module 4: The Complete TDD Workflow
Module 4: The Complete TDD Workflow with Claude Code
Module 4: The Complete TDD Workflow with Claude Code
Capsule overview
Phase 1 gave you the pieces: spec-first to think about tests first, unit tests to verify isolated logic, integration and E2E tests to verify components and flows. You have the techniques. What you don't have yet is the complete process.
This module assembles it all into an iterative workflow: red-green-refactor with Claude Code. You write a failing test (red) → Claude Code implements the code (green) → you refactor with the safety of passing tests. You repeat. Each feature is built cycle by cycle, test by test, incrementally.
But there's something that makes TDD with AI fundamentally different from classic TDD: the implementation arrives in seconds. The bottleneck is no longer writing code — it's the quality of your tests and your judgment to decide when to step in. When Claude Code fails a test, is the problem the implementation (let it iterate) or the spec (adjust the test)? That judgment is the real skill of this module.
Module Context
Where are we?
This is Module 4 — the first of Phase 2 (Testing Workflows).
What you already know (Phase 1):
- ✅ Spec-first methodology and TDD with AI (Module 1)
- ✅ Generating and evaluating unit tests with Claude Code (Module 2)
- ✅ Integration tests, E2E tests, the test pyramid (Module 3)
What's missing: The complete iterative process. Going from "I know how to write tests" to "I know how to build complete features with TDD and AI."
Where are we headed?
Phase 1: TDD Fundamentals with AI ✅
├── Module 1: ✅ Spec-first
├── Module 2: ✅ Unit tests
└── Module 3: ✅ Test pyramid
Phase 2: Testing Workflows
├── Module 4: ← YOU ARE HERE — The complete TDD workflow
├── Module 5: → Coverage and edge cases
└── Module 6: → Mocking, fixtures, validation loops
Phase 3: Final Project
├── Module 7: → Professional testing strategy
└── Module 8: → Capstone project
Phase 2 takes the pieces from Phase 1 and turns them into productive workflows. This module is the bridge — it transforms scattered techniques into a repeatable process.
Professional Objective
Master the complete TDD cycle with Claude Code: red → green → refactor, with the judgment to decide when to intervene and when to let Claude Code iterate.
By the end of this module you'll be able to:
- ✅ Run the complete TDD cycle: red test → Claude Code implements → validate → refactor
- ✅ Give Claude Code adequate context (test + interfaces + constraints)
- ✅ Decide when to intervene vs when to let Claude Code iterate
- ✅ Apply spec refinement: adjust tests when you discover the spec was incomplete
- ✅ Build a complete feature with multiple consecutive TDD cycles
- ✅ Keep the rhythm: small, incremental tests, cycles measured in minutes
Module Progression
Module Map
| Capsule | Topic | What you'll learn |
|---|---|---|
| 02 | Red-Green-Refactor with AI | The TDD cycle adapted for AI: differences from classic TDD, the agentic rhythm, the developer's role |
| 03 | Writing failing tests first | How to write effective red tests: small, incremental, one purpose per test |
| 04 | The Claude Code implement cycle | The implementation cycle: giving context, evaluating the result, iterating, when to step in |
| 05 | Refactoring with tests as a safety net | Refactoring without fear using green tests as a safety net |
| 06 | Project: A complete feature with TDD | Building a complete authentication system with multiple TDD cycles |
Learning flow
First you'll understand the adapted cycle (capsule 02): how red-green-refactor changes when Claude Code is your implementer. The rhythm is different, the bottleneck is different, and the developer's skill is different.
Then you'll master the cycle's input (capsule 03): writing red tests that are clear, small, and that give Claude Code enough information to implement correctly.
Next you'll learn the interaction with Claude Code (capsule 04): how to give context, what to do when it fails, when to adjust your prompt vs your test, and the framework for deciding when to step in.
Capsule 05 closes the cycle with refactoring: using the green tests as a safety net to improve the code without breaking functionality.
The project (capsule 06) integrates it all: building a complete authentication system with multiple TDD cycles, experiencing spec refinement, Claude Code's mistakes, and the real rhythm of the workflow.
Project Connection
This module's project: A complete feature with TDD
You'll build an authentication system (registration, login, tokens) using TDD with Claude Code. Each aspect starts as a test:
Cycle 1: test_register_validates_email → Claude implements validation
Cycle 2: test_register_hashes_password → Claude implements hashing
Cycle 3: test_register_creates_user → Claude implements registration
Cycle 4: test_login_returns_token → Claude implements login
Cycle 5: test_token_validates_correctly → Claude implements validation
...
The key isn't the final code — it's experiencing the process: multiple cycles, spec refinement when you discover something is missing, and the judgment of when to step in.
Connection with the final project (Module 8)
In the final project, every feature of the application is built exactly like this. The difference is the scale: here it's one feature, in Module 8 it's a complete application. If you master the rhythm here, the final project is simply "more cycles."
Boundaries: What This Module Will NOT Do
- ❌ Coverage metrics — Measured in Module 5. Here the focus is the process, not the numbers
- ❌ Mocking of external services — Covered in Module 6. Here we work with real logic
- ❌ CI/CD integration — Not part of this guide's scope
- ❌ Performance testing — The focus is functionality, not performance
- ❌ Deep debugging of Claude Code — We cover when to step in, not how to debug the model
Evidence of Success
By the end of this module, you'll know you succeeded if:
- ✅ You can describe your TDD process with AI step by step
- ✅ You can build a feature starting from a red test
- ✅ You know when the problem is your test vs Claude Code's implementation
- ✅ You can refactor code confidently because your tests back you up
- ✅ You completed the project: an authentication system built cycle by cycle with TDD
Summary
- ✅ This module transforms isolated techniques into a productive workflow
- ✅ The TDD cycle with AI: red test → Claude Code implements → validate → refactor
- ✅ The differentiating skill: knowing when to intervene vs when to let it iterate
- ✅ Small, incremental tests — each cycle should take minutes
- ✅ Spec refinement: tests evolve as you understand the problem better
- ✅ The project builds a real feature with multiple consecutive TDD cycles
Next capsule: Red-Green-Refactor with AI — the TDD cycle adapted for working with Claude Code.
Additional Resources
- Kent Beck: Test-Driven Development by Example - The original TDD book
- Martin Fowler: Refactoring - Refactoring techniques with tests
- Anthropic: Claude Code Docs - Official Claude Code documentation
- pytest Documentation - Complete pytest reference
- The Pragmatic Programmer: Red-Green-Refactor - Context and philosophy of the TDD cycle
Module 4 — Testing with Claude Code Guide From isolated techniques to a productive workflow