tdd

Guides test-driven development using the red-green-refactor loop with behavior-focused tests.

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/TrayMachi/dotfiles --skill tdd-traymachi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tdd
Source: https://github.com/TrayMachi/dotfiles/tree/main/agents/skills/tdd
Command: npx skills add https://github.com/TrayMachi/dotfiles --skill tdd-traymachi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing tests after implementation often produces brittle tests coupled to internal structure that break during refactors. This Skill enforces a disciplined test-first workflow where tests verify observable behavior through public interfaces, so they survive internal changes and read like specifications. ## Core Features & Use Cases - Red-Green-Refactor Workflow: Structures development as vertical slices with one test and one minimal implementation per cycle, avoiding the horizontal-slicing anti-pattern of writing all tests upfront. - Behavior-Focused Testing Guidance: Distinguishes good integration-style tests from implementation-coupled tests, with concrete examples of mocking boundaries, interface design, and deep modules. - Use Case: When building a new checkout feature, use this Skill to plan which behaviors to test, write a tracer-bullet test first, then iterate through incremental red-green cycles before refactoring duplication and deepening modules. ## Quick Start Use the tdd skill to build this feature test-first, one behavior at a time through the public interface.

Frequently Asked Questions about tdd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I practice test-driven development with red-green-refactor?

Write one failing test for a single behavior (red), write the minimal code to make it pass (green), then refactor while tests stay green. Repeat this cycle per behavior rather than writing all tests upfront, and never refactor while a test is failing.

What is the difference between good and bad unit tests?

Good tests verify observable behavior through public interfaces and survive internal refactors. Bad tests mock internal collaborators, test private methods, or assert on call counts, so they break whenever implementation changes even though behavior stays the same.

When should I use mocks in testing?

Mock only at system boundaries such as external APIs, payment gateways, time, and randomness. Never mock your own classes or internal collaborators, and design boundaries with dependency injection and SDK-style interfaces so each mock returns one specific shape.

Why do my tests break every time I refactor code?

Tests break during refactoring when they are coupled to implementation details like internal function names, private methods, or mock call expectations. Rewrite them to assert outcomes through the public interface so they describe what the system does, not how.

Should I write all tests before writing any implementation code?

No, writing all tests first is the horizontal-slicing anti-pattern and produces tests of imagined behavior. Use vertical slices instead: alternate one test with one minimal implementation so each test responds to what you learned from the previous cycle.