Agent skill

Test Driven Development

by jnMetaCode in jnMetaCode/superpowers-zh

“在实现任何功能或修复 bug 时使用,在编写实现代码之前”

— description from SKILL.md by jnMetaCode
MITAuto-check passedTesting & QA

Install Test Driven Development

skills CLI
$ npx skills add jnMetaCode/superpowers-zh --skill test-driven-development -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install jnMetaCode/superpowers-zh test-driven-development --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/jnMetaCode/superpowers-zh.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/test-driven-development .claude/skills/test-driven-development && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
test-driven-development
GitHub stars
8.3k
Token cost
~1.4k tokens
SKILL.md length
233 words
Files
2
Skills in repo
21
Repo updated
First seen
Licence
MIT

At a glance

  • SKILL.md covers 概述, 何时使用, 铁律 and 红-绿-重构, plus 8 more sections
  • Calls npm and cargo

About this skill

Test Driven Development is a skill in jnMetaCode/superpowers-zh (8.3k stars). Its SKILL.md is about 1.4k tokens, with 1 other file in the folder. Licence: MIT.

What it can do on your machine

Read from SKILL.md and the folder at commit fe34019. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npm
    • cargo

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Test Driven Development loads about 1.4k tokens when it runs. Until then it costs about 13 tokens; SKILL.md has 233 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~13
When it runs · the whole SKILL.md, loaded when a task matches
~1.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from jnMetaCode/superpowers-zh at commit fe34019, republished under its MIT licence (© jnMetaCode). 233 words, ~1,434 tokens.

Download SKILL.mdSave it as .claude/skills/test-driven-development/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
test-driven-development
description
在实现任何功能或修复 bug 时使用,在编写实现代码之前
version
1.0.0
license
MIT

测试驱动开发(TDD)

概述

先写测试。看它失败。写最少的代码让它通过。

核心原则: 如果你没有看到测试失败,你就不知道它是否测试了正确的东西。

违反规则的字面意思就是违反规则的精神。

何时使用

始终使用:

  • 新功能
  • Bug 修复
  • 重构
  • 行为变更

例外(需询问你的人类伙伴):

  • 一次性原型
  • 生成的代码
  • 配置文件

想着"就这一次跳过 TDD"?停下来。那是在给自己找借口。

铁律

没有失败的测试,就不写生产代码

先写了代码再写测试?删掉它。从头来过。

没有例外:

  • 不要保留作为"参考"
  • 不要在写测试时"改编"它
  • 不要看它
  • 删除就是删除

从测试出发,重新实现。句号。

红-绿-重构

dot
digraph tdd_cycle {
    rankdir=LR;
    red [label="红灯\n编写失败的测试", shape=box, style=filled, fillcolor="#ffcccc"];
    verify_red [label="验证正确失败", shape=diamond];
    green [label="绿灯\n最少代码", shape=box, style=filled, fillcolor="#ccffcc"];
    verify_green [label="验证通过\n全部绿灯", shape=diamond];
    refactor [label="重构\n清理代码", shape=box, style=filled, fillcolor="#ccccff"];
    next [label="下一个", shape=ellipse];

    red -> verify_red;
    verify_red -> green [label="是"];
    verify_red -> red [label="错误的\n失败"];
    green -> verify_green;
    verify_green -> refactor [label="是"];
    verify_green -> green [label="否"];
    refactor -> verify_green [label="保持\n绿灯"];
    verify_green -> next;
    next -> red;
}
红灯 - 编写失败的测试

写一个最小的测试来展示期望行为。

<Good>
```typescript
test('retries failed operations 3 times', async () => {
  let attempts = 0;
  const operation = () => {
    attempts++;
    if (attempts < 3) throw new Error('fail');
    return 'success';
  };

const result = await retryOperation(operation);

expect(result).toBe('success'); expect(attempts).toBe(3); });

名称清晰,测试真实行为,只测一件事
</Good>

<Bad>
```typescript
test('retry works', async () => {
  const mock = jest.fn()
    .mockRejectedValueOnce(new Error())
    .mockRejectedValueOnce(new Error())
    .mockResolvedValueOnce('success');
  await retryOperation(mock);
  expect(mock).toHaveBeenCalledTimes(3);
});

名称模糊,测试的是 mock 而非代码 </Bad>

要求:

  • 一个行为
  • 清晰的名称
  • 使用真实代码(除非不得已才用 mock)
验证红灯 - 看它失败

必须执行。绝不跳过。

bash
npm test path/to/test.test.ts

确认:

  • 测试失败(不是报错)
  • 失败信息符合预期
  • 失败原因是功能缺失(不是拼写错误)

测试通过了? 你在测试已有的行为。修改测试。

测试报错了? 修复错误,重新运行直到它正确地失败。

绿灯 - 最少代码

写最简单的代码让测试通过。

<Good>
```typescript
async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
  for (let i = 0; i < 3; i++) {
    try {
      return await fn();
    } catch (e) {
      if (i === 2) throw e;
    }
  }
  throw new Error('unreachable');
}
```
刚好够通过测试
</Good>
<Bad>
```typescript
async function retryOperation<T>(
  fn: () => Promise<T>,
  options?: {
    maxRetries?: number;
    backoff?: 'linear' | 'exponential';
    onRetry?: (attempt: number) => void;
  }
): Promise<T> {
  // YAGNI
}
```
过度设计
</Bad>

不要添加功能、重构其他代码或做超出测试要求的"改进"。

验证绿灯 - 看它通过

必须执行。

bash
npm test path/to/test.test.ts

确认:

  • 测试通过
  • 其他测试仍然通过
  • 输出干净(没有错误、警告)

测试失败了? 修改代码,不是测试。

其他测试失败了? 立即修复。

"其他测试"指的是项目的整个测试套件,不只是你那个文件。 你写的那个测试跑绿了,不等于测试套件是绿的。在宣称改动完成之前,运行项目的测试命令(直接 pytest、npm test、cargo test——仓库用什么就跑什么),即使你的任务只点名了一个测试文件。任务里的范围说明约束的是交付物,不是你的验证。那次运行暴露出的任何失败——包括不是你造成的——都要在报告里点名写出;一个你眼看着滚过去却没提的红色测试,就是一份靠遗漏造假的报告。

重构 - 清理代码

只有在绿灯之后才重构:

  • 消除重复
  • 改善命名
  • 提取辅助函数

保持测试绿灯。不要添加行为。

重复

为下一个功能写下一个失败的测试。

好的测试

特质好的差的
最小化只测一件事。名称中有"和"?拆分它。test('validates email and domain and whitespace')
清晰名称描述行为test('test1')
展示意图展示期望的 API掩盖了代码应该做什么

写任何测试、或修改任何测试时,阅读 writing-good-tests.md,那里是让测试保持诚实的规则:

  • 在动手写之前,先点名那个会让该测试失败的生产代码改动
  • 断言真实行为,绝不断言 mock 行为
  • 只有测试才用的代码放在测试工具里,不进生产类
  • 在 mock 一个依赖之前,先搞清它的副作用

常见借口

借口现实
"太简单了不用测"简单的代码也会出 bug。测试只需 30 秒。
"我之后补测试"后写的测试立即通过——而立即通过什么都证明不了。它可能测错了对象、测的是实现而不是行为、或者漏掉你忘了的那个边界情况。你从没看着它失败过,所以你从没证明它能抓住 bug。先写测试逼你看到那次失败。
"后补测试也能达到相同目的(重的是精神不是仪式)"后补测试回答的是"这做了什么?";先写测试回答的是"这应该做什么?"后写的测试已经被你写好的代码带偏了——你验证的是你记得的那些情况,而不是你本该发现的那些。有覆盖率,没有测试有效的证明。
"已经手动测试过了"手动测试是临时的:没有记录你覆盖了什么、代码一改就没法重跑、压力之下极易漏掉情况。"我试的时候是好的" ≠ 全面。自动化测试每次都以同样的方式运行。
"删除 X 小时的工作太浪费"沉没成本谬误——那些时间无论怎样都已经花掉了。真正的选择是:用 TDD 重写(高置信度)vs 留着它事后补测试(低置信度、很可能有 bug)。留着你无法信任的代码才是浪费。
"留作参考,然后先写测试"你会去改编它。那就是后补测试。删除就是删除。
"需要先探索一下"可以。探索完了扔掉,从 TDD 开始。
"测试难写 = 设计不清楚"听测试的。难以测试 = 难以使用。
"TDD 会拖慢我"TDD 就是务实的那条路:在提交前抓住 bug、防止回归、让你能无所畏惧地重构。所谓"务实"的抄近道,等于在生产环境里调试——更慢,不是更快。
"手动测试更快"手动测试无法证明边界情况。每次修改你都得重新测。
"现有代码没有测试"你在改进它。为现有代码补测试。

危险信号 - 停下来,从头开始

  • 先写了代码再写测试
  • 实现完了才补测试
  • 测试立即通过
  • 无法解释测试为什么失败
  • "之后再补"测试
  • 说服自己"就这一次"
  • "我已经手动测试过了"
  • "后补测试也能达到相同目的"
  • "重要的是精神不是仪式"
  • "留作参考"或"改编现有代码"
  • "已经花了 X 小时了,删掉太浪费"
  • "TDD 太教条了,我是在务实"
  • "这次情况不同,因为……"

以上所有情况都意味着:删除代码。用 TDD 从头开始。

示例:Bug 修复

Bug: 空邮箱被接受了

红灯

typescript
test('rejects empty email', async () => {
  const result = await submitForm({ email: '' });
  expect(result.error).toBe('Email required');
});

验证红灯

bash
$ npm test
FAIL: expected 'Email required', got undefined

绿灯

typescript
function submitForm(data: FormData) {
  if (!data.email?.trim()) {
    return { error: 'Email required' };
  }
  // ...
}

验证绿灯

bash
$ npm test
PASS

重构 如果需要,提取验证逻辑以支持多个字段。

验证清单

在标记工作完成之前:

  • 每个新函数/方法都有测试
  • 在实现之前看到每个测试失败
  • 每个测试因预期原因失败(功能缺失,不是拼写错误)
  • 为每个测试编写了最少代码使其通过
  • 所有测试通过
  • 输出干净(没有错误、警告)
  • 测试使用真实代码(只在不可避免时用 mock)
  • 覆盖了边界情况和错误场景

不能全部勾选?你跳过了 TDD。从头开始。

遇到困难时

问题解决方案
不知道怎么测试写出你期望的 API。先写断言。问你的人类伙伴。
测试太复杂设计太复杂。简化接口。
必须 mock 所有东西代码耦合太紧。使用依赖注入。
测试 setup 太庞大提取辅助函数。还是复杂?简化设计。

调试集成

发现 bug?写一个重现 bug 的失败测试。按 TDD 循环走。测试既证明了修复有效,又防止了回归。

绝不在没有测试的情况下修复 bug。

最终规则

生产代码 → 测试存在且先失败
否则 → 不是 TDD

没有你的人类伙伴的许可,没有例外。

© jnMetaCode, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in skills/test-driven-development of jnMetaCode/superpowers-zh.

  • SKILL.md
  • writing-good-tests.md

Open the folder on GitHubat commit fe34019

Compare with similar skills

Test Driven Development next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Test Driven Development compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Test Driven Development this skilljnMetaCode/superpowers-zh8.3k—~1.4kAutomated safety check: PassMIT
TDDpietheinstrengholt/rssmonster56430 repos~906Automated safety check: PassMIT
TDD WorkflowhellangleZ/burn-in-cceverywhere-ralph11211 repos~2.4kAutomated safety check: PassNone
TDDsanity-io/sanity6.4k20 repos~1kAutomated safety check: PassMIT
Test Driven Developmentfarm-fe/farm5.6k51 repos~2.5kAutomated safety check: PassMIT
Tapd Story PipelineTencentBlueKing/bk-bcs840—~2.6kAutomated safety check: PassCustom licence

Similar skills

  • TDD

    pietheinstrengholt/rssmonster

    Test-driven development. An agent skill from pietheinstrengholt/rssmonster.

    564 GitHub starsUsed in 30 repos~906 tokens
    Testing & QAAuto-check passed
  • TDD Workflow

    hellangleZ/burn-in-cceverywhere-ralph

    A skill your agent uses when writing new features, fixing bugs, or refactoring code.

    112 GitHub starsUsed in 11 repos~2.4k tokens
    Testing & QAAuto-check passed
  • TDD

    sanity-io/sanity

    Official

    Test-driven development with red-green-refactor loop. An agent skill from sanity-io/sanity.

    6.4k GitHub starsUsed in 20 repos~1k tokens
    Testing & QAAuto-check passed
  • A skill your agent uses when implementing any feature or bugfix, before writing implementation code

    5.6k GitHub starsUsed in 51 repos~2.5k tokens
    Testing & QAAuto-check passed
  • Tapd Story Pipeline

    TencentBlueKing/bk-bcs

    单需求实现流水线——把一个 TAPD 需求从零推进到代码提交。自动串联技术澄清、 开发计划、任务拆分、TDD 实现、架构/安全校验、代码提交六个阶段。

    840 GitHub stars~2.6k tokensUpdated today
    Testing & QAAuto-check passed
  • Absolute Init

    maddhruv/absolute

    One-time setup for absolute: interview how you want it to behave (output style, autonomy, TDD strictness, spec dir, families) + detect the stack once, then write .absolute.config.json (project…

    218 GitHub starsUsed in 1 repo~3k tokens
    Testing & QAAuto-check passed

More from jnMetaCode/superpowers-zh

All 21 skills in this repo
  • Brainstorming Before Building

    jnMetaCode/superpowers-zh

    Turns a rough idea into an approved design before any code is written, sorting the request into spike, bounded or architectural and enforcing an approval gate.

    8.3k GitHub stars~1.8k tokensUpdated 3 days ago
    Auto-check passed
  • Chinese Commit Conventions

    jnMetaCode/superpowers-zh

    Reference for Chinese-language git commits and changelogs: Conventional Commits adapted for Chinese teams, with templates, breaking-change notes and issue links for several platforms.

    8.3k GitHub starsUsed in 1 repo~1.6k tokens
    Auto-check passed
  • Inline Plan Execution

    jnMetaCode/superpowers-zh

    Executes a written implementation plan task by task in the current session, with a progress ledger, test-first gates and one fresh-context review at the end.

    8.3k GitHub stars~2.5k tokensUpdated 3 days ago
    Auto-check passed
  • Git Worktree Isolation

    jnMetaCode/superpowers-zh

    Sets up an isolated workspace before feature work or plan execution, preferring native worktree tools and falling back to git worktree, with instructions in Chinese.

    8.3k GitHub starsUsed in 1 repo~982 tokens
    Auto-check passed
  • Agency Orchestrator Workflow Runner

    jnMetaCode/superpowers-zh

    Runs agency-orchestrator YAML workflows inside the current agent session, with the session's own model playing each role in turn and no API key needed.

    8.3k GitHub starsUsed in 1 repo~885 tokens
    Auto-check passed
  • Chinese Code Review Etiquette

    jnMetaCode/superpowers-zh

    Gives Chinese-language templates and priority labels for code review feedback, plus guidance on bilingual comments, commit messages and common team anti-patterns.

    8.3k GitHub stars~1.2k tokensUpdated 3 days ago
    Auto-check passed

Categories

Questions about Test Driven Development

How do I install Test Driven Development in Claude Code?

Run `npx skills add jnMetaCode/superpowers-zh --skill test-driven-development -a claude-code`. Or copy the skill folder (skills/test-driven-development in jnMetaCode/superpowers-zh) into .claude/skills/test-driven-development in your project. Claude Code loads it when a task matches its description.

How do I install Test Driven Development in Codex?

Run `npx skills add jnMetaCode/superpowers-zh --skill test-driven-development -a codex`. Or copy the skill folder (skills/test-driven-development in jnMetaCode/superpowers-zh) into .agents/skills/test-driven-development in your project. Codex loads it when a task matches its description.

Can I use Test Driven Development in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add jnMetaCode/superpowers-zh --skill test-driven-development -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/test-driven-development, .gemini/skills/test-driven-development, .github/skills/test-driven-development and .opencode/skills/test-driven-development in your project.

What does Test Driven Development need to run?

Going by SKILL.md and its folder, Test Driven Development needs the command-line tools its instructions call (npm and cargo).

Does Test Driven Development access the network?

SKILL.md contains no URLs. Its commands use npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Test Driven Development safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Test Driven Development use?

Test Driven Development is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Test Driven Development use?

About 1.4k tokens (SKILL.md is roughly 5.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Test Driven Development?

Skills that share tags, products or a category with Test Driven Development: TDD (pietheinstrengholt/rssmonster, 564 stars), TDD Workflow (hellangleZ/burn-in-cceverywhere-ralph, 112 stars), TDD (sanity-io/sanity, 6.4k stars) and Test Driven Development (farm-fe/farm, 5.6k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Test Driven Development?

jnMetaCode (a GitHub user) maintains it in jnMetaCode/superpowers-zh, which has 8,270 GitHub stars. The repository holds 21 skills in this directory. The repository was last updated on October 4, 2026.

Source: jnMetaCode/superpowers-zh on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.