AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Test Driven Development

skill-5tldr-claude-skills-test-driven-development · by 5tldr

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

No reviews yet
0 installs
26 views
0.0% view→install

Install

$ agentstack add skill-5tldr-claude-skills-test-driven-development

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-5tldr-claude-skills-test-driven-development)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
7mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Test Driven Development? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

测试驱动开发 (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%但质量低
  • 忽略边界条件

✅ 建议

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

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.