
Test-Driven Development
FreeMaster the red-green-refactor cycle for effective testing.
Free · Opens the source repo
What Test-Driven Development does
Test-Driven Development (TDD) is a software development approach that emphasizes writing tests before the actual code. This skill serves as a comprehensive reference for developers looking to implement TDD effectively. It outlines the essential principles of the red-green-refactor cycle, ensuring that tests are not only created but are also meaningful and maintainable. By consulting this skill, developers can learn what constitutes a good test, how to identify appropriate seams for testing, and recognize common anti-patterns that can lead to ineffective tests.
A key aspect of TDD is understanding what a good test is. The skill explains that tests should verify behavior through public interfaces rather than internal implementation details. This means that as the code evolves, the tests remain stable and focused on the expected outcomes. The documentation provides examples of good tests and guidelines for mocking, helping developers create tests that are resilient to changes in the underlying code structure.
Additionally, the skill emphasizes the importance of seams—defined boundaries where tests should be placed. It advises developers to agree on these seams before writing tests, ensuring that testing efforts are concentrated on critical paths rather than every conceivable edge case. This strategic approach helps streamline the development process and enhances code quality.
Lastly, the skill outlines common anti-patterns to avoid in TDD, such as implementation-coupled tests and tautological assertions. By adhering to the rules of the TDD loop—writing failing tests first, focusing on one slice of functionality at a time, and separating refactoring from the implementation cycle—developers can create a more efficient and effective testing workflow. This skill is particularly beneficial for developers and teams committed to maintaining high-quality code through rigorous testing practices.
When to use it
Use this skill when you want to adopt TDD practices for building features or fixing bugs, especially if you're focused on writing tests first.
When not to use it
This skill may not be suitable for projects that do not prioritize testing or for teams unfamiliar with TDD principles.
What you can build with it
Implementing TDD in a New Project
When starting a new software project, use this skill to establish a TDD workflow from the beginning, ensuring that tests are integral to the development process.
Refactoring Existing Code
If you need to refactor existing code, consult this skill to write tests that verify the behavior of the current implementation before making changes.
Training Team on TDD Practices
Use this skill as a training resource for your development team to align on TDD principles and improve overall code quality.
How to install Test-Driven Development
View source1. Install with the skills CLI
npx skills add mattpocock/skills/tdd --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by mattpocockTest-Driven Development
TDD is the red → green loop. This skill is the reference that makes that loop produce tests worth keeping: what a good test is, where tests go, the anti-patterns, and the rules of the loop. Every section applies on every cycle — consult them before and during the loop, not after.
When exploring the codebase, read CONTEXT.md (if it exists) so test names and interface vocabulary match the project's domain language, and respect ADRs in the area you're touching.
What a good test is
Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't. A good test reads like a specification — "user can checkout with valid cart" tells you exactly what capability exists — and survives refactors because it doesn't care about internal structure.
See tests.md for examples and mocking.md for mocking guidelines.
Seams — where tests go
A seam is the public boundary you test at: the interface where you observe behavior without reaching inside. Tests live at seams, never against internals.
Test only at pre-agreed seams. Before writing any test, write down the seams under test and confirm them with the user. No test is written at an unconfirmed seam. You can't test everything — agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.
Ask: "What's the public interface, and which seams should we test?"
When the shape of that interface is itself in question — how deep the module is, where the seam belongs, what the interface should expose — use the /codebase-design skill for the vocabulary. It is the shared source of the module, interface, depth, seam, adapter, leverage and locality terms, and it is a reference to consult, not a session to run.
Anti-patterns
- Implementation-coupled — mocks internal collaborators, tests private methods, or verifies through a side channel (querying the database instead of using the interface). The tell: the test breaks when you refactor but behavior hasn't changed.
- Tautological — the assertion recomputes the expected value the way the code does (
expect(add(a, b)).toBe(a + b), a snapshot derived by hand the same way, a constant asserted equal to itself), so it passes by construction and can never disagree with the code. Expected values must come from an independent source of truth — a known-good literal, a worked example, the spec. - Horizontal slicing — writing all tests first, then all implementation. Bulk tests verify imagined behavior: you test the shape of things rather than user-facing behavior, the tests go insensitive to real changes, and you commit to test structure before understanding the implementation. Work in vertical slices instead — one test → one implementation → repeat, each test a tracer bullet that responds to what the last cycle taught you.
Rules of the loop
- Red before green. Write the failing test first, then only enough code to pass it. Don't anticipate future tests or add speculative features.
- One slice at a time. One seam, one test, one minimal implementation per cycle.
- Refactoring is not part of the loop. It belongs to the review stage (see the
code-reviewskill), not the red → green implementation cycle.
Frequently asked questions about Test-Driven Development
Similar skills
Spring Boot Testing
Master testing techniques for Spring Boot 4 applications.
GitHub Issues
Manage GitHub issues efficiently with MCP tools.
Geofeed Tuner
Optimize your IP geolocation feeds in CSV format.
Batch Files
Master Windows batch scripting for automation and task management.
Adobe Illustrator Scripting
Automate your Illustrator workflows with ExtendScript.
Plugin Structure
Create and organize Claude Code plugins effectively.
