跳到正文
Skillpedia
测试48k · #5935

tdd-workflows-tdd-green

它能做什么

这个工具可以帮你写出让失败的测试通过所需的最少代码。它专注于解决眼前的问题,让测试重新跑通。

适用场景

  • ✓代码测试失败,你需要尽快修复时。
  • ✓开始开发一个新功能,第一步是让某个测试通过时。
  • ✓只想实现必要功能,让代码按预期运行时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd-workflows-tdd-green/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd-workflows-tdd-green/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我的商品列表测试失败了,请生成最小代码让它通过。”

每周 5 个新技能,1 分钟读完。

工作原理

这个工具会分析能让失败测试通过的最小代码改动。它会实施这个小修复,并检查测试是否已经通过,同时避免添加不必要的复杂度。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Green Phase: Simple function

def product_list(request): products = Product.objects.all() return JsonResponse({'products': list(products.values())})

Refactor: Class-based view

class ProductListView(View): def get(self, request): products = Product.objects.all() return JsonResponse({'products': list(products.values())})

Refactor: Generic view

class ProductListView(ListView): model = Product context_object_name = 'products'


### Express Patterns

**Inline → Middleware → Service Layer:**
```javascript
// Green Phase: Inline logic
app.post('/api/users', (req, res) => {
  const user = { id: Date.now(), ...req.body };
  users.push(user);
  res.json(user);
});

// Refactor: Extract middleware
app.post('/api/users', validateUser, (req, res) => {
  const user = userService.create(req.body);
  res.json(user);
});

// Refactor: Full layering
app.post('/api/users',
  validateUser,
  asyncHandler(userController.create)
);

Use this skill when

  • Moving from red to green in a TDD cycle
  • Implementing minimal behavior to satisfy tests
  • You want to keep implementation intentionally simple

Do not use this skill when

  • You are refactoring for design or performance
  • Tests are already passing and you need new requirements
  • You need a full architectural redesign

Instructions

  1. Review failing tests and identify the smallest fix.
  2. Implement the minimal change to pass the next test.
  3. Run tests after each change to confirm progress.
  4. Record shortcuts or debt for the refactor phase.

Safety

  • Avoid bypassing tests to make them pass.
  • Keep changes scoped to the failing behavior only.

Resources

  • resources/implementation-playbook.md for detailed patterns and examples.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题

TDD 中的“绿色阶段”是什么意思?

在 TDD(测试驱动开发)中,“绿色阶段”指的是所有代码测试都已通过的状态。

为什么要只写最少的代码?

只写最少的代码可以避免不必要的复杂度,确保你解决的是测试指出的那个具体问题,这样以后也更容易维护。

什么时候应该停止使用这个工具?

当测试已经通过,并且你需要添加新功能时,或者当你的目标是改进整体代码设计,而不只是修复某个测试时,就应该停止使用。

详情

作者的原始描述

Implement the minimal code needed to make failing tests pass in the TDD green phase.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5935
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能