tdd-master

A test-driven development guide: TDD means writing a test that fails, making it pass with the smallest change, and then cleaning up the design.

In plain words
What is it for?
Use it when building a feature or fixing a bug by defining small behaviors, checking whether the design is testable, and following the red-green-refactor cycle.
Why use it?
It provides quick feedback while coding and keeps tests focused on observable behavior instead of fragile internal details.

Skill for Claude CodeCodexCursor

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 skills/programmeranthony/expert-coding-harness/tdd-master
Any agent
npx skills add ProgrammerAnthony/Expert-Coding-Harness --skill tdd-master
Clone the repo
git clone --depth 1 https://github.com/ProgrammerAnthony/Expert-Coding-Harness

Made for: Claude Code, Codex, Cursor.

Per session 83 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,019 The whole file, excluding the scripts and references it only reads on demand.
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.00083 $0.02019
Opus 5 $0.00042 $0.01009
Sonnet 5 $0.00017 $0.00404
Haiku 4.5 $0.00008 $0.00202

Measured 2d ago against content hash a8c31ca3fc0b, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

tdd-master 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 2d ago.

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.

.cursor/skills/tdd-master/SKILL.md · 205 lines

How it starts

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

TDD 开发大师

铁律:没有失败的测试,不写一行生产代码。 先写代码再补测试的,必须删掉先写的代码重来。

核心哲学

竖向切片,而非横向切片

反模式(横向切片):先把所有测试写完,再一口气写所有实现

  • 问题:测试套件成为规格书,不是活文档;实现阶段难以获得快速反馈

正确做法(竖向 tracer bullet 切片):每次选一个最小可验证行为,完成 RED→GREEN→REFACTOR 完整循环

  • 每个切片都是端到端的最小功能(一个完整行为)
  • 通过测试可以立即运行并得到结果

测试测行为,而非测实现

# 错误:测试内部实现(脆弱,重构即失效)
def test_calls_validate_method():
    service = UserService()
    with patch.object(service, '_validate') as mock:
        service.create_user(data)
    mock.assert_called_once()

# 正确:测试可观察行为(稳健,重构不影响)
def test_create_user_returns_user_id():
    service = UserService()
    user_id = service.create_user({"name": "Alice", "email": "[email protected]"})
    assert isinstance(user_id, int)
    assert user_id > 0

工作流

阶段一:规划(获得用户批准前禁止写代码)

1.1 接口设计

先设计公共接口,不暴露内部实现细节:

询问用户:这个功能/模块需要提供什么公共接口?
输出:函数/方法签名 + 输入/输出类型 + 前置/后置条件

加载 references/testing-principles.md 检查接口设计原则。

1.2 行为清单

将功能拆解为可测试的行为列表:

待实现的行为:
- [ ] 正常路径:[描述]
- [ ] 边界条件:[描述]
- [ ] 错误路径:[描述]
- [ ] 并发场景:[如适用]

每个行为必须是:独立可测试 + 有明确期望结果 + 最小粒度

1.3 可测试性检查

评估设计是否可测试(加载 references/testing-principles.md):

  • 依赖是否可以被替换(Mock/Stub)?
  • 是否有隐藏的全局状态?
  • 是否混合了业务逻辑和 I/O?

将设计展示给用户确认,批准后才开始实现。


阶段二:RED-GREEN-REFACTOR 循环

每次选一个行为(从行为清单第一项开始):

RED 阶段
  1. 写最小的失败测试

    • 测试名称描述行为(test_用户注册成功返回用户ID
    • 只测一个行为
    • 使用尽可能真实的代码(避免过度 mock)
  2. 强制验证 RED(不可跳过):

pytest tests/test_user.py::test_用户注册成功返回用户ID -v

确认:测试因正确原因失败(功能未实现),而非因测试代码错误失败

  1. RED 失败则停止:如果无法让测试变红,说明测试本身有问题,先修复测试
GREEN 阶段
  1. 写最小的实现:只写让当前测试通过所需的最少代码

    • 可以暂时硬编码(如 return 42),只要测试通过
    • 禁止超前实现"以后会用到的"功能
  2. 强制验证 GREEN(不可跳过):

    pytest tests/test_user.py -v
    

    确认:全部测试通过,包括之前的测试

  3. GREEN 失败则停止:回到实现代码修复,不重构,不写新测试

Read the full file on GitHub · 205 lines

Files

What ships with it

5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 2d ago First seen · 205 lines · 83 tokens per session scan A a8c31ca3fc0b

Subscribe to this mod's changes

tdd-master is a skill published in the GitHub repository ProgrammerAnthony/Expert-Coding-Harness (235 stars, last pushed 3mo ago), licensed MIT. It adds 83 tokens to every session and 2,019 once invoked, about $0.0004 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.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

chat-pet-sprite-creation

Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.

microsoft/vscode · 53 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens

babysit-pr

Babysit a GitHub pull request after creation by continuously polling review comments, CI checks/workflow runs, and mergeability state until the PR is merged/closed or user help is required. Diagnose failures, retry likely flaky failures up to 3 times, auto-fix/push branch-related issues when appropriate, and keep…

openai/codex · 114 tokens

imagegen

Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output…

openai/codex · 113 tokens

agent-host-chat-contributions

Build and review cross-cutting agent-host chat behavior through lifecycle contributions. Use when adding turn lifecycle side effects, prompt or context injection, restored-history transformation, protocol-action observation, or when reviewing changes that add code to AgentSideEffects or AgentService.

microsoft/vscode · 56 tokens