Test-Driven Development
Implement a behavior by first demonstrating its failure, then making the smallest passing change.
npx skills add obra/superpowers --skill test-driven-development What it does
A test written after an implementation may only confirm the assumptions already encoded in that implementation. This skill guides the agent through a test-first cycle so the check demonstrates the missing behavior before the code is added.
What changes after install
- Starts each behavior with a test that fails for the intended reason.
- Separates the minimal passing change from later refactoring.
- Runs relevant wider checks before claiming the change is complete.
Install
Run this command with Node.js 22.20 or later and select your agent in the Skills CLI.
npx skills add obra/superpowers --skill test-driven-development Before using Test-Driven Development
- Have access to the implementation and a runnable test framework. Be able to run a targeted test and observe its failure before making the behavior pass.
Read the reviewed setup instructions for the selected workflow.
When to use it
- Adding a deterministic feature with observable inputs and outputs.
- Fixing a bug that can be reproduced as a regression test.
When not to use it
- Claiming broad product correctness because one narrow test passes.
- Using mocks without understanding the real dependency behavior.
Turn a defect into an observable example
Suppose a date filter excludes records created on the final day of a selected range. Provide a small dataset, the requested dates, and the expected records. Ask the agent to write a regression check that fails because the boundary behavior is wrong. A test that fails only because a module cannot be imported has not yet demonstrated the bug.
The skill describes a cycle of establishing the failure, adding the smallest implementation that satisfies it, and then improving the code while keeping the tests passing. This separates behavior changes from cleanup and makes it easier to understand why a change is necessary.
Use the project’s real tools
The workflow is not a particular test runner. It needs a working project environment and an appropriate way to execute tests. Reuse the existing framework and fixture conventions where possible. Mock dependencies when isolation is necessary, but avoid testing only that a mock returns the value you configured.
For a browser interaction or external integration, decide which part a unit test can establish and which part needs a broader check. A narrow passing test should not be described as proof of the entire user flow.
Review the evidence
Look for the initial failure, the implementation change, the passing result, and relevant regression checks. If a supposedly reproducing test never failed, investigate what it actually covers. Systematic Debugging helps identify the cause before the fix; this skill helps turn the chosen behavior into a regression guard. SkillDex reviewed the instructions and did not measure their effectiveness in a live coding task.
Related workflows
FAQ
- What if the first test passes immediately?
- Check whether it actually exercises the missing behavior. A passing test does not demonstrate the defect you intended to fix.
- Is a failing import the required initial failure?
- Not usually. The useful failure shows the expected behavior is absent, rather than an unrelated setup or syntax problem.