tdd

Guides test-driven development using the red-green-refactor loop with vertical slicing.

Updated Nov 23, 2024
One-click install
npx skills add https://github.com/tokisakiyuu/dotfiles --skill tdd-tokisakiyuu
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tdd
Source: https://github.com/tokisakiyuu/dotfiles/tree/main/home/dot_claude/skills/tdd
Command: npx skills add https://github.com/tokisakiyuu/dotfiles --skill tdd-tokisakiyuu

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing tests after implementation often produces tests coupled to internal structure that break during refactors, while writing all tests upfront produces tests of imagined behavior. This Skill enforces a disciplined red-green-refactor workflow that keeps tests focused on observable behavior through public interfaces. ## Core Features & Use Cases - Red-Green-Refactor Loop: Drives one test and one minimal implementation at a time using vertical tracer-bullet slices instead of horizontal batching. - Behavior-Focused Test Design: Provides guidelines and examples for writing integration-style tests that survive refactors, plus rules for when mocking at system boundaries is appropriate. - Interface Design Guidance: Includes references on deep modules, dependency injection, and testability-oriented interface design. - Use Case: When asked to build a new feature like a checkout flow, the Skill plans the public interface with the user, writes one failing test, implements the minimal code to pass, and repeats until all prioritized behaviors are covered. ## Quick Start Ask the assistant to build a feature or fix a bug using test-driven development with the red-green-refactor loop.

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 keeping tests green. Repeat this cycle per behavior rather than writing all tests upfront.

What is the difference between vertical and horizontal test slicing?▼

Vertical slicing alternates one test with one implementation in a tracer-bullet pattern, while horizontal slicing writes all tests first then all code. Horizontal slicing produces tests of imagined behavior that break during refactors.

When should I use mocks in unit tests?▼

Mock only at system boundaries such as external APIs, time, randomness, and sometimes databases or file systems. Never mock your own classes or internal collaborators, since that couples tests to implementation details.

Why do my tests break every time I refactor code?▼

Tests break during refactoring when they verify implementation details like private methods, internal call counts, or mock interactions instead of observable behavior. Rewrite them to exercise public interfaces and assert on outcomes users care about.

How do I design interfaces that are easy to test?▼

Accept dependencies as parameters instead of constructing them internally, return results rather than producing side effects, and keep the surface area small. Dependency injection makes external collaborators trivially replaceable in tests.