TDD: Failing Test Before Code

VerifiedSafe

Red-green loop: write the smallest failing test before the code, know when to skip the loop honestly, and what evidence to report.

Sby Skills Guide Bot
TestingIntermediate
11/2/2026
Claude CodeCursorWindsurfCopilotCodex
#tdd#unit-testing#regression-testing#red-green-refactor#test-design

Recommended for

Automated summary

A test-driven development method that requires writing the smallest failing test before the code, and justifying any decision to skip the loop.

Strengths

  • Seven-step red-green-clean loop that insists on reading the failure reason before writing code
  • Honest skip criteria (brittle mocks, slow end-to-end infrastructure, fixture churn) plus an obligation to state out loud why the test was skipped
  • Clear guardrails: never weaken an assertion, never edit an existing test to match a suspect implementation
  • Demands concrete evidence: the test name, the failure seen before the fix, and the green run afterwards

Limitations

  • Language- and framework-agnostic: it defers to project conventions and gives no concrete assertion syntax
  • Does not address integration or end-to-end strategy, performance testing, or property-based tests
  • Effectiveness relies on the agent actually running the tests, which the skill can only request
When to use it

When starting behaviour that has a cheap test path, or fixing a bug that can be reproduced in a test.

When not to use it

When the change is exploratory, visual, or infrastructure-level and the only available test would be slow, end-to-end, or mock-heavy.

Security analysis

Safe
Quality score90/100

This is a pure instructional document about test-driven development. It declares no tools, contains no code, no shell commands, no network or file operations, and no attempts to alter agent behavior beyond ordinary workflow guidance. There is no execution surface and no instruction-injection content.

No concerns found

How this analysis is made

Examples

Failing test first for a new behaviour
Add a rate limit to our /login endpoint using TDD: write a failing test for the 6th attempt within a minute, then implement the smallest code that makes it pass.
Reproduce a bug in a test
Bug: parse_duration('1h30m') returns None instead of 5400. Reproduce it in a test that fails on current main, then fix it and show me the passing run.
Decide whether to skip the loop
This fix touches our Celery worker startup and signal handling. Tell me whether the test path is worth it here; if not, say why and name the check you used instead.

name: tdd description: Write the failing test before the code that satisfies it, for new behaviour and for bug fixes, and stop when the test path is not worth its cost. Covers the red-green loop, what a first test should assert, when to skip the loop honestly, and the evidence to report. Use when starting behaviour that has a cheap test path, or fixing a bug that can be reproduced in a test. Triggers - "tdd", "write a failing test first", "regression test", "reproduce this in a test", "test first".

TDD

Make the behaviour executable before making it work. The point is not ceremony: a test written first describes what the caller needs, while a test written after describes what the code happens to do.

Write the test in the style the project already uses. Where the project ships a test skill for the language, that skill wins. Failing that, read two neighbouring test files and follow them. Failing both, the shape is: named as a sentence, built from setup, mock, test and verify blocks separated by blank lines, and carrying no comments.

That shape is also the fastest way to write step 2. Name the behaviour, write the verify block first, then work backwards to the setup that makes it reachable.

The loop

  1. Name the behaviour. One sentence, in the caller's terms. That sentence is the test name, and if it will not come out as a sentence the behaviour is not understood well enough to write yet.
  2. Write the smallest failing test. It asserts the behaviour, never the implementation you are about to write.
  3. Run it, and read the failure. It must fail for the reason you expect. A test that passes immediately is testing something else. A test that fails on a missing import is not evidence yet.
  4. Write the smallest code that passes. Not the general case, not the version with the options object nobody asked for.
  5. Run it again. Green.
  6. Clean up while green. Both sides: the code, and the test that is now longer than it needs to be.
  7. Repeat for the next behaviour, not the next line.

For a bug, the same loop with step 1 fixed for you: the test is the reproduction, and it must fail before the fix and pass after it.

What the first test asserts

The behaviour a caller would notice. Not the shape of an intermediate value, not the number of times a collaborator was called, not a snapshot of a structure.

Start at the boundary that is cheap to call. The unit is whatever has a real seam, which is often a function two layers in rather than the exported one.

When to skip

Do not force a test. Skip the loop when the only available test would need broad harness setup, brittle mocks, slow end-to-end infrastructure, production-only state, or a fixture churn larger than the change.

Skipping is a decision you say out loud, not one you make silently. Name why the test path is not worth it and what you did instead: a script, a manual reproduction, a screenshot from the real app, a log assertion.

Prefer no test to a bad test. A bad test is one that mostly exercises mocks, encodes the implementation, depends on timing or global state, or would be deleted the moment it had proved the fix.

Guardrails

  • Never change an existing test to match a wrong implementation.
  • Never weaken an assertion to get to green. Either the behaviour changed, and the test name changes with it, or there is a bug.
  • Keep a regression test focused on its bug. Unrelated coverage is a separate change.
  • A flaky bug still gets a deterministic test. Pin the signal, not the timing.
  • If the bug is one of a class, land the focused test first and consider the siblings after.

Report the evidence

Not "added a test". Name the test, the failure it produced before the fix, and the run that passed after. If failing-first could not be shown, say why, and name the check used instead.

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/tdd-failing-test-before-code-mveranxa' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/tdd-failing-test-before-code-mveranxa/download' --output '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md.part' && mv '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md.part' '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md' && test -s '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/tdd' && cp -R '.skill-downloads/tdd-failing-test-before-code-mveranxa' '.claude/skills/tdd'

Cursor
test -f '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md' && test -s '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/tdd' && cp -R '.skill-downloads/tdd-failing-test-before-code-mveranxa' '.cursor/skills/tdd'

Codex
test -f '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md' && test -s '.skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/tdd' && cp -R '.skill-downloads/tdd-failing-test-before-code-mveranxa' '.agents/skills/tdd'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/tdd-failing-test-before-code-mveranxa'

openskills read 'tdd-failing-test-before-code-mveranxa'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/tdd-failing-test-before-code-mveranxa/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills