writing-tests
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.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 192
- Forks
- 31
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
Write or rewrite text in plain, layman-readable English in the spirit of ASD-STE100 Simplified Technical English: short sentences, active voice, simple tenses, one word one meaning, condition before command, every technical term defined at first use, no AI slop. Default mode is Plain. Strict mode applies full STE vocabulary compliance when the user names STE, ASD-STE100, or compliance. Use for documentation, READMEs, runbooks, procedures, error messages, release notes, incident reports, API guides, and explanations for readers outside the field. Also use when the user says "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", or asks for docs that translate well. The same rules govern the reply: answer first, prose only.
code-review
Review guidance for pull requests in this repository. Use when reviewing a pull request, to keep comments on evidence you can see rather than on predicted build outcomes, remembered API signatures, or assumed conventions.
cargo-anvil-adoption
Complete cargo-anvil adoption in an existing Rust repository after the first cargo anvil run. Use when generated Anvil files coexist with legacy CI, recipes, scripts, tool configuration, or validation failures.