一键导入
common-test-driven-development
Guides the agent to always write unit tests first (TDD) when creating or modifying code, ensuring tests drive implementation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guides the agent to always write unit tests first (TDD) when creating or modifying code, ensuring tests drive implementation.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Defines the analyse-plan-execute workflow that the agent must follow for non-trivial tasks.
Defines a strict code review process where the agent validates quality through linting, tests, complexity analysis, and critical challenge of design decisions.
Guides the agent through creating a new AI skill following the agentskills.io format and this repository's conventions.
Guides the agent to always write commit messages following the Conventional Commits 1.0.0 specification, ensuring structured, parseable, and semantically meaningful commit history.
Guides the agent through applying Domain-Driven Design principles when modeling, structuring, and implementing business logic.
Guides the agent through applying Hexagonal Architecture (Ports & Adapters) to isolate domain logic from external concerns within a service.
| name | common-test-driven-development |
| description | Guides the agent to always write unit tests first (TDD) when creating or modifying code, ensuring tests drive implementation. |
Write unit tests before or alongside implementation code, following a test-driven development approach to ensure correctness and prevent regressions.
Use this skill when:
Check for existing tests first. Before writing any implementation code, search the codebase for existing test files related to the code you are about to change.
*.test.*, *.spec.*, *_test.*, test_*.*, or a tests//__tests__/ directory.Write a simple failing test first. Before implementing any logic:
it should return the sum of two numbers or test_empty_list_returns_none).Make the test pass with minimal implementation. Write only enough production code to make the failing test pass (green phase).
Refactor while keeping tests green. Once the test passes:
Repeat for additional behavior. For each new piece of behavior:
Test quality rules.
Test structure. Follow the Arrange-Act-Assert (AAA) or Given-When-Then pattern:
Edge cases. After the happy path passes, add tests for:
Run the full related test suite. After all changes are complete, run the full test suite for the affected module or package to ensure no regressions.
Never skip tests to save time. If you are creating code, you are creating tests. There is no scenario where production code is written without a corresponding test. If pressed for time, reduce scope — but every line of implemented scope must have test coverage.
Step 1 — Write failing test:
test("adds two positive numbers", () => {
expect(add(2, 3)).toBe(5);
});
Step 2 — Minimal implementation:
function add(a, b) {
return a + b;
}
Step 3 — Test passes. Refactor if needed (nothing to refactor here).
Step 4 — Next test:
test("returns 0 when both arguments are 0", () => {
expect(add(0, 0)).toBe(0);
});
Step 5 — Already passes. Move to next behavior.
Scenario: You need to change a function's return type from number to string.
1. Run existing tests — they pass.
2. Identify which assertions will break due to the intentional change.
3. Update ONLY those assertions to expect the new string return type.
4. Confirm updated tests fail (since implementation hasn't changed yet).
5. Change the implementation.
6. Confirm all tests pass.