测试驱动开发 (TDD)

SkillDev tools

Test-Driven Development (TDD) guide based on Kent Beck's 'TDD By Example'. Use for: (1) writing or planning code tests, (2) learning or applying the TDD methodology, (3) understanding TDD patterns and workflows such as red-green-refactor, (4) creating test frameworks or test infrastructure, (5) refa

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the 测试驱动开发 (TDD) skill

What this skill tells your AI

The instructions your AI receives, as published by onweekendd/screenwright in .claude/skills/tdd/SKILL.md and read by ahel’s review.

核心循环:红-绿-重构

1. 红   - 编写一个失败的测试
2. 绿   - 让测试通过(快速、简单)
3. 重构 - 消除重复

核心理念:TDD不是一定要用微小的步骤,而是有能力在需要时用微小的步骤。

快速开始

待办列表:
$5 + 10 CHF = $10,汇率2:1
$5 × 2 = $10
将amount设为私有
处理副作用?
  1. 先写测试 - 想象完美的API接口
  2. 让它编译 - 创建桩类、桩方法
  3. 让它运行 - 假数据,硬编码返回值
  4. 消除重复 - 消除测试与代码之间的依赖

参考指南

按主题组织的详细模式和示例:

主题参考文档
TDD核心模式core-patterns.md
编写测试test-writing.md
重构策略refactoring.md
xUnit模式xunit-patterns.md
TDD中的设计模式design-patterns.md

核心原则

测试先行

  • 通过可预测的反馈降低压力
  • 创建良性循环:更多测试 → 更少压力 → 更多测试
  • 永远距离绿条只有一次改动

隔离测试

  • 测试之间不能相互影响
  • 执行顺序无关
  • 强制高内聚、低耦合

断言先行

  • 从断言开始,反向推导到设置代码
  • 分离"正确答案是什么"与设计决策
  • 自然地揭示API

测试列表

  • 开始前列出所有需要的测试
  • 实现过程中添加新发现的测试
  • 团队协作时,离开前确保所有测试通过

Signals

GitHub stars
31
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
tdd-onweekendd
Source
github.com/onweekendd/screenwright