tdd

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

11|2|Updated Dec 29, 2025
One-click install
npx skills add https://github.com/oskrgab/petrodb --skill tdd-oskrgab
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tdd
Source: https://github.com/oskrgab/petrodb/tree/main/.agents/skills/tdd
Command: npx skills add https://github.com/oskrgab/petrodb --skill tdd-oskrgab

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing tests after code often produces brittle tests coupled to implementation details that break during refactors. This Skill enforces a disciplined test-first workflow where each test verifies observable behavior through public interfaces, producing a test suite that survives internal restructuring. ## Core Features & Use Cases - Red-Green-Refactor Loop: Structures work as vertical slices where one failing test drives one minimal implementation, repeated incrementally. - Behavior-Focused Testing Guidance: Distinguishes good integration-style tests from bad implementation-coupled tests, with concrete examples of each. - Interface Design Support: Provides principles for deep modules, dependency injection, and mockable 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, and refactor only after all tests are green. ## Quick Start Use the tdd skill to build the new user registration feature test-first, one behavior at a time.

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.

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, breaking whenever implementation changes without behavior changing.

When should I use mocks in testing?

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 are coupled to implementation details like private methods, internal mocks, or call-order assertions. Rewrite them to verify behavior through public interfaces 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 horizontal slicing and produces tests of imagined behavior. Use vertical slices instead: one test, one implementation, repeated, so each test responds to what you learned from the previous cycle.