一键导入
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when implementing any feature or bugfix, before writing implementation code
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when starting any conversation - establishes how to find and use skills, requiring skill tool invocation before ANY response including clarifying questions.
Use when exploring or modifying a codebase and you need a cheap structural map of files, directories, imports, exports, or direct members before reading full source.
Guide for writing ast-grep rules to perform structural code search and analysis. Use when searching codebases using AST patterns, finding specific language constructs, or executing complex structural code queries.
You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.
Review changes since a fixed ref along two axes (Standards & Spec) using parallel sub-agents. Use when reviewing branches, PRs, or diffs.
Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies
| name | test-driven-development |
| description | Use when implementing any feature or bugfix, before writing implementation code |
Write the test first. Watch it fail. Write minimal code to pass. If you didn't watch the test fail, you don't know if it tests the right thing.
Always: New features, bug fixes, refactoring, and behavior changes. Exceptions (requires partner permission): Throwaway prototypes, generated code, configuration files.
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
If you wrote implementation code before the test, delete it entirely and start over. No adapting or using it as reference. Delete means delete.
Write a single minimal test demonstrating the desired behavior. Avoid vague assertions or mock-dependent tests.
test('retries failed operations 3 times', async () => {
let attempts = 0;
const result = await retryOperation(async () => {
attempts++;
if (attempts < 3) throw new Error('fail');
return 'success';
});
expect(result).toBe('success');
expect(attempts).toBe(3);
});
Run the test (npm test path/to/test.test.ts). Confirm it fails for the expected reason (feature missing) and not typos or syntax errors. If it passes or errors, fix the test first.
Write the absolute simplest, minimal code to pass the test. Do not over-engineer or add unrelated features (YAGNI).
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');
}
Run tests to confirm the new test passes, other tests still pass, and output is clean without console errors/warnings.
Improve naming, remove duplication, and simplify helpers /only/ while keeping tests green. Do not add new behavior.
Bug: Empty email accepted on form submission.
// 1. RED
test('rejects empty email', async () => {
const result = await submitForm({ email: '' });
expect(result.error).toBe('Email required');
}); // Verify RED: FAIL: expected 'Email required', got undefined
// 2. GREEN
function submitForm(data: { email: string }) {
if (!data.email?.trim()) return { error: 'Email required' };
} // Verify GREEN: PASS
| Problem | Solution |
|---|---|
| Don't know how to test | Write the desired API first, write assertions backward, or ask your human partner. |
| Test is too complicated | Interface or design is too complex. Redesign to simplify and decouple. |
| Must mock everything | Code is too coupled. Use dependency injection and real implementations. |
| Test setup is huge | Extract setup helpers or simplify the design. |
When a bug is found, write a failing test that reproduces it, verify the failure, and fix it using the standard TDD cycle. Never deploy fixes without an automated test.
@testing-anti-patterns.md).Production code → test exists and failed first
Otherwise → not TDD. No exceptions.