单元测试编写
writing-tests
在添加或更改测试时应用本仓库的测试策略。通过公共 API 和测试工具测试公共行为。 保持测试具有确定性、快速且独立于真实 I/O。 对于公共 API 无法覆盖的实现细节,使用单元测试。
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 193
- Forks
- 32
01 前言 Front Matter
- name
- writing-tests
- description
- Apply this repository's test policy when you add or change tests. Test public behavior through public APIs and test utilities. Keep tests deterministic, fast, and independent of real I/O. Use unit tests for implementation details that public APIs cannot exercise.
03 SKILL.md 正文
Writing tests
This skill is the repository guide for developer agents that write tests.
Review agents use the stricter rules in
.github/skills/code-review/test-review.md.
Test behavior through public APIs
Test public behavior and API contracts through the public API. Put these tests
under crates/<crate>/tests/.
Use test utilities to control collaborators and state. A public integration test does not need real network, process, filesystem, or clock I/O.
When a test needs more control, expose test-only public APIs behind a
non-default test-util feature. Enable this feature in the integration test
and use these APIs to inject fakes, clocks, scripted I/O, or other controlled
dependencies. Do not add test-only APIs to the default public surface.
Use unit tests for implementation details that a supported public API cannot exercise. Keep these tests close to the implementation.
Keep tests deterministic and fast
Control all inputs and dependencies. Do not depend on test order, host state, wall-clock time, random values, external services, or developer credentials.
Prefer these workspace tools:
- Use
fakeableto create controlled fakes and mocks. - Use
future_assertto test future behavior without starting a runtime. - Use a frozen
tickclock and advance time explicitly. - Use
instasnapshots for exact string and structured output.
Target less than one second for each test, excluding compilation. Prefer in-memory values and injected collaborators.
Preserve behavior tests during implementation changes
If a refactor or performance change preserves public behavior, do not rewrite existing integration tests to match internal implementation details. Add tests when the change needs more coverage.
If a change intentionally alters public behavior, update the affected tests. Describe the contract and test changes clearly in the pull request.
Do not weaken assertions, skip tests, or delete coverage to make a change pass.
04 同仓库更多 Skills
简明英语写作与改写
simple-english
以 ASD-STE100 简化技术英语(Simplified Technical English)的理念,用浅显易懂、外行也能读懂的英语撰写或改写文本: 短句、主动语态、简单时态、一词一义、先条件后指令、每个技术术语首次出现时给出定义、不写 AI 套话。 默认模式为 Plain(简明)。当用户提及 STE、ASD-STE100 或合规要求时,Strict(严格)模式将全面遵守 STE 词汇规范。 适用于文档、README、运行手册、流程规程、错误消息、发布说明、事件报告、API 指南,以及面向领域外读者的解释性内容。 当用户说 "STE"、"Simplified Technical English"、"ASD-STE100"、"plain English"、"layman's terms"、"explain it simply"、"no jargon"、"de-slop"、"make this readable"、"write for non-native readers",或要求撰写易于翻译的文档时,也应使用本技能。 同样的规则也适用于回复:先给答案,只用散文叙述。
PR 代码评审
code-review
本仓库拉取请求(Pull Request)的评审指南。适用于评审拉取请求时,使评审意见聚焦于你能看到的证据,而非对构建结果的预测、记忆中的 API 签名或臆定的约定。
Rust 项目 cargo-anvil 接入
cargo-anvil-adoption
在首次运行 cargo anvil 后,在现有 Rust 仓库中完成 cargo-anvil 的采用落地。当生成的 Anvil 文件与遗留 CI、recipes、脚本、工具配置或验证失败共存时使用。