tdd

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

Updated May 23, 2026
One-click install
npx skills add https://github.com/Oatse/CWE-Automation --skill tdd-oatse
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tdd
Source: https://github.com/Oatse/CWE-Automation/tree/main/.agents/skills/tdd
Command: npx skills add https://github.com/Oatse/CWE-Automation --skill tdd-oatse

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing tests after code (or all tests before code) produces brittle tests coupled to implementation details that break on every refactor. This Skill enforces a disciplined test-first workflow where tests verify behavior through public interfaces and survive internal changes. ## Core Features & Use Cases - Red-Green-Refactor Workflow: Drives one test at a time through tracer-bullet cycles, avoiding the horizontal-slicing anti-pattern of writing all tests upfront. - Behavior-Focused Test Design: Provides guidelines for writing integration-style tests through public APIs, with mocking restricted to system boundaries like external APIs, time, and file systems. - Interface Design Guidance: Includes references on deep modules, dependency injection, and testable interface design to keep test surfaces small. - Use Case: When building a new checkout feature, use this Skill to plan which behaviors to test, write one failing test, implement minimal code to pass, and repeat until the feature is complete, then refactor safely. ## 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 one test at a time rather than writing all tests upfront, so each test responds to what you learned from the previous cycle.

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: external APIs, databases, time, randomness, and file systems. Never mock your own classes or internal collaborators. 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 on refactor when they are coupled to implementation details like internal function names, private methods, or mock call expectations. Rewrite them to verify behavior through the public interface, describing what the system does rather than how it does it.

Should I write all tests before writing any implementation code?

No. Writing all tests first is horizontal slicing and produces tests of imagined behavior coupled to data shapes. Use vertical slices instead: one test, one implementation, repeated, so each test reflects real behavior you just built.