test-driven-development

A coding rule that requires tests to be written before implementation code. TDD, or test-driven development, repeats a cycle of writing a failing test, making it pass, and then improving the code.

In plain words
What is it for?
Use it for new features, bug fixes, and other changes, writing one focused test at a time and waiting for user review before implementing each behavior.
Why use it?
It makes the intended behavior explicit early and helps catch regressions, edge cases, and error-handling problems.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/barisercan/cursorrules/test-driven-development
Clone the repo
git clone --depth 1 https://github.com/barisercan/cursorrules
Per session 1,054 This file is loaded in full into every session.
When invoked 1,054 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01054 $0.01054
Opus 5 $0.00527 $0.00527
Sonnet 5 $0.00211 $0.00211
Haiku 4.5 $0.00105 $0.00105

Measured yesterday against content hash 62a2dce6c8e9, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

test-driven-development scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

test-driven-development.mdc · 135 lines

How it starts

The opening of the file, as written. The whole thing — 135 lines — stays where its author put it; the contents beside it link to each section on GitHub.


description: Enforce test-driven development with atomic steps and user verification at each stage globs: "**/*" alwaysApply: true

Test-Driven Development Rule

Enforce test-driven development practices with atomic steps and user verification.

actions:

  • type: enforce message: | TEST-DRIVEN DEVELOPMENT PROTOCOL

    MANDATORY TDD WORKFLOW:

    1. ALWAYS START WITH TESTS:

      • Plan and write tests BEFORE writing implementation code
      • Create tests for every new feature, bug fix, or change
      • Follow Red-Green-Refactor cycle
    2. ATOMIC TEST STEPS:

      • Write ONE test at a time
      • Keep each test focused on a single behavior
      • Do not write long test suites all at once
      • Stop after each atomic test step
    3. USER VERIFICATION REQUIRED:

      • After writing each test, wait for user verification
      • Let user review and approve test before proceeding
      • Only continue to implementation after test approval
      • User must confirm each step before moving forward
    4. COVERAGE REQUIREMENTS:

      • Aim for full or near-full test coverage
      • Cover edge cases and error scenarios
      • Test both positive and negative paths
      • Document any untested code with clear reasoning
    5. FRAMEWORK DEPENDENCY:

      • Use testing frameworks specified by user
      • Follow user's testing patterns and conventions
      • Ask user to specify testing approach if unclear
      • Adapt to existing test structure in codebase
    6. INCREMENTAL APPROACH:

      • Small, verifiable steps only
      • No large code blocks without tests
      • Each implementation should make tests pass
      • Refactor only after tests are green
    7. CONTINUOUS TESTING:

      • Any change to src/ directory triggers all tests
      • Must ensure all tests pass before proceeding
      • Fix broken tests immediately
      • No code changes without verified test coverage

    WORKFLOW STEPS:

    1. Understand requirement
    2. Write failing test (Red)
    3. STOP - Get user verification
    4. Write minimal code to pass test (Green)
    5. RUN ALL TESTS - Ensure nothing breaks
    6. STOP - Get user verification
    7. Refactor if needed (Refactor)
    8. RUN ALL TESTS - Verify refactor didn't break anything
    9. STOP - Get user verification
    10. Repeat for next atomic feature

    AUTO-TEST TRIGGER:

    • Any file modification under src/ automatically runs: pytest tests/ -v
    • Must address any test failures before continuing development
    • Ensures continuous validation and early error detection

examples:

  • input: | User: "Add a login function"

    Correct TDD approach:

    Step 1: "I'll write a test for login function first. Here's the failing test..." [Wait for user approval] Step 2: "Now I'll implement minimal code to make this test pass..." [Wait for user approval] Step 3: "Let's refactor and add the next test case..." output: "Following TDD with atomic steps and user verification"

  • input: | User: "Fix the bug in calculation"

    Correct TDD approach:

    Step 1: "I'll write a test that reproduces the bug first..." [Wait for user approval] Step 2: "Now I'll fix the code to make the test pass..." output: "Bug fix following TDD principles"

Read the full file on GitHub · 135 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 135 lines · 1,054 tokens per session scan A 62a2dce6c8e9

Subscribe to this mod's changes

test-driven-development is a cursor rule published in the GitHub repository barisercan/cursorrules (35 stars, last pushed 1y ago), licensed MIT. It adds 1,054 tokens to every session, about $0.0053 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.