通过先写失败测试再实现代码,帮助稳定完成功能开发与缺陷修复。
复制安装指令,让 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.
<good-example>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.
</good-example> <bad-example>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.
<good-example> ```typescript async function retryOperation<T>(fn: () => Promise<T>): Promise<T> { for (let i = 0; i < 3; i++) { try { return await fn(); } catch (e) { if (i === 2) throw e; } } throw new Error('unreachable'); } ``` Just enough to pass </good-example> <bad-example> ```typescript async function retryOperation<T>( fn: () => Promise<T>, options?: { maxRetries?: number; backoff?: 'linear' | 'exponential'; onRetry?: (attempt: number) => void; } ): Promise<T> { // YAGNI } ``` Over-engineered </bad-example>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.
将长期复杂任务拆分为可执行小步骤,减少上下文超限与遗漏
通过结构化追问与方案比较,把模糊想法梳理成可执行设计。
帮助你严谨评估代码评审意见,澄清疑点后再决定是否采纳与实现
用四阶段系统化排查框架定位缺陷根因,再制定可靠修复方案。
在编写或修改测试时识别反模式,避免错误 mock 与污染生产代码。
帮助你实现与迭代界面和交互体验,完成前端集成与设计优化。
帮助开发者编写关注行为、抗重构且可验证修复意图的高质量测试。
在实现完成后协助提交代码、推送分支并发起拉取请求与自动审查。
沉淀并查询代码库经验教训,帮助开发、验证与评审减少重复踩坑。
快速修复代码格式、Lint与常见错误,帮助提交前顺利通过 CI 检查
系统化排查测试失败、构建中断与异常运行问题,帮助快速恢复开发进度
帮助你为复杂问题编写调试测试并反复验证,快速定位异常根因。