test-driven-development

Red-green-refactor discipline for writing code driven by tests. Covers the TDD cycle, test quality, mocking boundaries, and design for testability. Use when: implementing features, fixing bugs, refactoring existing code, designing module interfaces, or working within vertical slices from a tracer-bullets workflow.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "test-driven-development" with this command: npx skills add oakoss/agent-skills/oakoss-agent-skills-test-driven-development

Test-Driven Development

Write one failing test that describes the next behavior, write the minimal code to pass it, then refactor while green. Every production change starts with a test that proves the need exists. This is the discipline within each vertical slice — not framework syntax, but when and why to write tests.

Skip for exploratory prototyping, config-only changes (environment variables, feature flags), visual/CSS-only tweaks, and one-off scripts that won't be maintained.

Quick Reference — TDD Cycle

PhaseActionRule
REDWrite one test that fails for the right reasonNo production code without a failing test
GREENWrite the simplest code that makes the test passResist the urge to generalize prematurely
REFACTORImprove structure while all tests stay greenNever change behavior and structure at once

Quick Reference — Principles

PrinciplePractice
One test at a timeComplete the full red-green-refactor cycle before writing the next test
Behavior over implementationTest what code does, not how it does it; assert outputs and side effects
Vertical slicesTDD one end-to-end behavior at a time, not one layer at a time
Mock at boundariesMock I/O, network, filesystem, clock. Never mock internal collaborators
Deep modulesDesign small interfaces with rich internals; fewer tests cover more behavior
Refactor only when greenAll tests pass before touching structure; refactoring under red hides new bugs
Design through testsThe first test IS the API design decision; awkward tests signal awkward interfaces
Failing test for every bugReproduce the bug as a failing test before writing the fix

Planning Before Coding

StepActionOutput
1Identify behaviorsList of observable behaviors the feature must exhibit
2Order by dependencySequence where each test builds on prior passing tests
3Design the interfaceFunction signatures, parameter types, return types
4Identify mock boundariesExternal dependencies that need test doubles

Common Mistakes

MistakeCorrect Pattern
Writing all tests firstOne test at a time. Complete the cycle before starting the next
Testing private methodsTest through the public interface; private methods are implementation detail
Mocking internal collaboratorsOnly mock at I/O boundaries; trust your own code
Writing code before a failing testRED first. The failing test proves the behavior is missing
Refactoring while tests are redGet to GREEN first, then refactor with confidence
Tests coupled to call sequencesAssert on outputs and state, not on which internal methods were called
Skipping the refactor phaseGREEN is not done. Clean up duplication and naming before moving on
Hardcoding expected valuesUse triangulation: add a second test case to force the general solution
One giant test per featureOne test per behavior — small, focused, independently meaningful

Delegation

  • Slice decomposition: If the tracer-bullets skill is available, use it to decompose features into vertical slices before applying TDD within each slice
  • Test framework syntax: Delegate framework-specific patterns to vitest-testing, e2e-testing, or api-testing skills
  • Feature planning: If the plan-first-development skill is available, use it for upfront planning before entering the TDD cycle
  • Individual TDD cycles: Delegate each red-green-refactor cycle to a Task subagent to keep context focused

References

  • Test Quality — good vs bad tests, what to test, naming, triangulation, refactoring signals
  • Mocking Boundaries — boundary rule, test doubles, dependency injection, anti-patterns
  • Design for Testability — deep modules, interface-first design, pure functions, computation vs I/O

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

github-cli

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

tanstack-cli

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

test-driven-development

No summary provided by upstream source.

Repository SourceNeeds Review