tdd

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

Updated Jun 30, 2026
One-click install
npx skills add https://github.com/santoshkal/chezmoi --skill tdd-santoshkal
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tdd
Source: https://github.com/santoshkal/chezmoi/tree/main/private_dot_config/opencode/skills/tdd
Command: npx skills add https://github.com/santoshkal/chezmoi --skill tdd-santoshkal

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 behavior through public interfaces, so they survive internal changes and read like specifications. ## Core Features & Use Cases - Red-Green-Refactor Workflow: Structures development as one test, one minimal implementation, repeated incrementally via tracer bullets instead of writing all tests upfront. - Behavior-Focused Test Design: Distinguishes good integration-style tests from implementation-coupled tests, with concrete examples of each. - Interface and Mocking Guidance: Provides rules for dependency injection, deep modules, and mocking only at system boundaries. - Use Case: When building a new checkout feature, use this Skill to plan which behaviors to test, write one failing test at a time, implement minimal code to pass, then refactor with confidence. ## Quick Start Use the tdd skill to build the new feature test-first, one behavior at a time 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 tests stay green. Repeat this loop one behavior at a time rather than writing all tests upfront.

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 without behavior changing.

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 prefer dependency injection plus SDK-style interfaces to make boundary mocking straightforward.

Why should I avoid writing all tests before implementation?▼

Writing all tests first (horizontal slicing) produces tests of imagined behavior coupled to data shapes and signatures. Vertical slices with one test then one implementation let each test respond to what you learned from the previous cycle.

When is it safe to refactor during TDD?▼

Refactor only after all tests pass, never while RED. Look for duplication, long methods, shallow modules, feature envy, and primitive obsession, running tests after each refactor step.