agentleFS
5tldr5tldr/claude-skills/skills/test-driven-development/SKILL.md

test-driven-development

Skill9 starsChanged 10 months agoMITView on GitHub

测试驱动开发,红-绿-重构循环

190 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use chinese-code-review, chinese-commit-conventions and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Leodorareluctant259Skill

    chinese-code-review

    中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈

    Also in 8 projects that use this

  • Leodorareluctant259Skill

    chinese-commit-conventions

    中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化

    Also in 8 projects that use this

  • obraSkill

    diagnosing-superpowers

    Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

    Also in 19 projects that use this

  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 39 projects that use this

  • LLl0k0laDSkill

    git-workflow-and-versioning

    Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

    Also in 47 projects that use this

  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 15 projects that use this

  • +3 more from Leodorareluctant259
  • +3 more from LLl0k0laD

The file

Files
SKILL.md

测试驱动开发 (TDD)

基于 obra/superpowers 的 TDD 方法论。

核心原则

先写测试,再写代码。红-绿-重构。

触发条件

当用户需要实现新功能、修复 Bug、或重构代码时激活。

TDD 循环

🔴 红:写失败的测试

1. 明确要实现的功能
2. 写一个测试用例
3. 运行测试,确认失败
4. 失败原因应该是功能未实现

🟢 绿:写最少的代码让测试通过

1. 只写让测试通过的代码
2. 不要过度设计
3. 不要写额外功能
4. 运行测试,确认通过

🔵 重构:改进代码质量

1. 在测试保护下重构
2. 消除重复代码
3. 改善命名和结构
4. 运行测试,确认仍然通过

工作流程

┌─────────────────────────────────────┐
│                                     │
│   ┌─────────┐                       │
│   │  🔴 红   │ ← 写失败的测试        │
│   └────┬────┘                       │
│        │                            │
│        ▼                            │
│   ┌─────────┐                       │
│   │  🟢 绿   │ ← 写最少代码通过测试   │
│   └────┬────┘                       │
│        │                            │
│        ▼                            │
│   ┌─────────┐                       │
│   │  🔵 重构 │ ← 改进代码质量        │
│   └────┬────┘                       │
│        │                            │
│        └────────────────────────────┘
│                  重复
└─────────────────────────────────────┘

输出格式

# 🧪 TDD 实现记录

## 功能需求
[需求描述]

## 实现计划
1. [ ] [测试用例1]
2. [ ] [测试用例2]
3. [ ] [测试用例3]

---

## 迭代1

### 🔴 红:测试用例
```[语言]
// 测试代码

运行结果:❌ 失败 失败原因:[原因]

🟢 绿:实现代码

// 实现代码

运行结果:✅ 通过

🔵 重构

[重构说明,如果有的话]


迭代2

[同上格式]


最终代码

测试文件

// 完整测试代码

实现文件

// 完整实现代码

测试覆盖

  • 语句覆盖:X%
  • 分支覆盖:X%
  • 函数覆盖:X%

## 测试类型

### 单元测试
  • 测试单个函数/方法
  • 隔离外部依赖
  • 快速执行
  • 高覆盖率

### 集成测试
  • 测试模块间交互
  • 包含真实依赖
  • 验证接口契约
  • 中等执行速度

### 端到端测试
  • 测试完整流程
  • 模拟用户行为
  • 验证业务场景
  • 执行较慢

## 测试金字塔
    /\
   /  \
  / E2E \      ← 少量
 /──────\
/  集成   \    ← 适量

/──────────
/ 单元 \ ← 大量 /──────────────\


## 最佳实践

### 测试命名

// 格式:should_[预期行为]when[条件] test('should return empty array when input is empty') test('should throw error when user not found')


### 测试结构 (AAA)

// Arrange - 准备 const input = [1, 2, 3]

// Act - 执行 const result = sum(input)

// Assert - 断言 expect(result).toBe(6)


### FIRST 原则

F - Fast(快速) I - Independent(独立) R - Repeatable(可重复) S - Self-validating(自验证) T - Timely(及时)


## 常见陷阱

### ❌ 避免
- 先写代码再补测试
- 测试依赖执行顺序
- 测试实现细节而非行为
- 测试覆盖率追求100%但质量低
- 忽略边界条件

### ✅ 建议
- 严格遵循红-绿-重构
- 每个测试独立运行
- 测试公开接口和行为
- 关注有意义的覆盖率
- 覆盖边界和异常情况

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.