tdd

Guides test-driven development using the red-green-refactor loop with seam-based testing.

Updated May 9, 2024
One-click install
npx skills add https://github.com/AceCodePt/dotfiles --skill tdd-acecodept
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: tdd
Source: https://github.com/AceCodePt/dotfiles/tree/main/.config/opencode/skills/tdd
Command: npx skills add https://github.com/AceCodePt/dotfiles --skill tdd-acecodept

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing tests after implementation often produces brittle, implementation-coupled tests that break on every refactor. This Skill enforces a disciplined test-first workflow so tests verify behavior through public interfaces and survive code changes. ## Core Features & Use Cases - Red-Green Loop Rules: Enforces writing a failing test first, then only enough code to pass it, one vertical slice at a time. - Seam Identification: Requires agreeing on public interface seams with the user before any test is written, focusing effort on critical paths. - Anti-Pattern Detection: Flags implementation-coupled, tautological, and horizontally-sliced tests with concrete good/bad examples. - Mocking Guidelines: Restricts mocks to system boundaries like external APIs, time, and file systems, with dependency injection patterns. - Use Case: When building a checkout feature, use this Skill to write a failing test like "user can checkout with valid cart" first, then implement just enough code to make it pass. ## Quick Start Use the tdd skill to build this feature test-first, starting by agreeing on the seams we should test.

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 on a new feature?▼

Start by agreeing on the seams, the public interfaces where tests will live, then write one failing test, implement just enough code to pass it, and repeat. Work in vertical slices of one test and one implementation per cycle rather than writing all tests upfront.

What is a seam in test-driven development?▼

A seam is the public boundary where you observe behavior without reaching inside the code. Tests live at seams and never against internals, so they survive refactors. Before writing tests, write down the seams under test and confirm them with the user.

When should I use mocks in unit tests?▼

Mock only at system boundaries such as external APIs, databases, time, randomness, and the file system. Never mock your own classes or internal collaborators. Use 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 refactoring when they are coupled to implementation details, such as mocking internal collaborators, testing private methods, or asserting on call counts. Rewrite them to verify observable behavior through public interfaces instead.

What is a tautological test and why is it bad?▼

A tautological test recomputes the expected value the same way the code does, so it passes by construction and can never catch a bug. Expected values must come from an independent source such as a known literal, a worked example, or the specification.