通过先写失败测试再实现代码,帮助稳定完成功能开发与缺陷修复。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "test-driven-development" 技能: 1. 下载 https://raw.githubusercontent.com/microsoft/FluidFramework/main/.agency/plugins/nori/skills/test-driven-development/SKILL.md 2. 保存为 ~/.claude/skills/test-driven-development/SKILL.md 3. 装好后重载技能,告诉我可以用了
请用测试驱动开发方式实现一个用户注册接口:先列出测试用例并编写会失败的测试,再给出最小实现代码让测试通过,最后简要说明可如何重构。技术栈使用 Node.js + Express + Jest。
一组先失败后通过的测试、对应的最小实现代码,以及简短重构建议。
我有一个结算金额计算错误的 bug。请先根据这个问题描述编写一个能复现问题的失败测试,再给出最小修复代码,并补充 2 个边界测试防止回归。语言使用 Python,测试框架用 pytest。
包含缺陷复现测试、最小修复方案和额外回归测试的完整 TDD 结果。
下面是一段难以测试的旧代码。请用 TDD 思路帮我重构:先识别可观察行为并设计失败测试,再逐步拆分模块并给出最小改动实现,确保每一步都能通过测试。输出按步骤组织。
分步骤的测试设计、渐进式重构方案和每步对应的实现建议。
Write failing tests (RED phase)
Create a subagent using the nori-task-runner to evaluate test quality.
.claude/skills/creating-debug-tests-and-iteratingWrite one minimal test showing what should happen.
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 foobar.retryOperation(operation);
expect(result).toBe('success');
expect(attempts).toBe(3);
});
Clear name, tests real behavior, one thing. Note that the tested operation is imported -- this is a STRONG sign that this is testing something real.
test('retry works', async () => {
const mock = jest
.fn()
.mockRejectedValueOnce(new Error())
.mockRejectedValueOnce(new Error())
.mockResolvedValueOnce('success');
await retryOperation(mock);
expect(mock).toHaveBeenCalledTimes(3);
});
Vague name, tests mock not code </bad-example>
npm test path/to/test.test.ts
Confirm:
Write simplest code to pass the test.
Don't add features, refactor other code, or "improve" beyond the test.
npm test path/to/test.test.ts
Confirm:
After green only:
Keep tests green. Do not add behavior.
帮助你严谨评估代码评审意见,澄清疑点后再决定是否采纳与实现
沉淀并查询代码库经验教训,帮助开发、验证与评审减少重复踩坑。