一键导入
automatic-testing
Principles and patterns for writing effective tests. Use when writing unit, integration, or end-to-end tests, or reviewing test quality.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Principles and patterns for writing effective tests. Use when writing unit, integration, or end-to-end tests, or reviewing test quality.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
How to conduct and receive effective code reviews. Use when reviewing a PR, requesting review, or improving review quality.
Systematic process for diagnosing and resolving defects. Use when debugging failures, investigating errors, or reproducing issues.
Principles for writing READMEs, API docs, ADRs, code comments, and changelogs. Use when creating or improving any technical documentation.
How to use Automatic's feature tracking system — creating, progressing, and updating per-project work items via the Automatic MCP service. Activate when working on a project managed by Automatic that has feature tracking enabled.
Data-driven approach to identifying and resolving performance bottlenecks. Use when investigating slow queries, high latency, or memory growth.
Techniques for improving code structure without changing behaviour. Use when cleaning up code, reducing complexity, or addressing technical debt.
| name | automatic-testing |
| description | Principles and patterns for writing effective tests. Use when writing unit, integration, or end-to-end tests, or reviewing test quality. |
| authors | ["Automatic"] |
Tests are executable specifications. They prove that code does what it claims, and protect against future regressions. A test suite you do not trust is worse than none — it creates false confidence.
Test behaviour, not implementation. Tests should describe what the code does, not how it does it. If refactoring internals breaks a test without changing observable behaviour, the test is wrong.
One reason to fail. Each test should assert one logical outcome. Tests that check multiple unrelated things are hard to diagnose when they fail.
Tests must be deterministic. A test that sometimes passes and sometimes fails is not a test — it is noise. Eliminate all sources of non-determinism: random seeds, timestamps, network calls, file system state.
Fast tests get run. Slow tests get skipped. Keep unit tests under 50ms each. Use integration and end-to-end tests sparingly and deliberately.
Test a single function or class in isolation. All dependencies are replaced with fakes, stubs, or mocks.
Test two or more real components working together. May use a real database, real file system, or real HTTP client against a test server.
Test the full system from the outside — as a user would interact with it.
Follow the Arrange / Act / Assert pattern in every test:
// Arrange — set up the state required for the test
// Act — perform the single action being tested
// Assert — verify the outcome
Name tests as full sentences describing behaviour:
// Good: "returns an empty list when no items match the filter"
// Bad: "test_filter" or "testFilter"
Use the simplest double that meets your needs:
| Type | Use when |
|---|---|
| Stub | You need a dependency to return a specific value |
| Fake | You need a working but simplified implementation (e.g. in-memory database) |
| Mock | You need to verify that a specific call was made with specific arguments |
| Spy | You need to record calls without changing behaviour |
Avoid mocking what you do not own. Mock at the boundary of your system.
Before committing a test, verify: