AGENT SKILL
rust-tests-guidelines
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 67
- Forks
- 24
02 资源文件 9
- 参考文档README.md2.2 KB
- 参考文档reference/compatibility-md.md1.5 KB
- 参考文档reference/config-schema.md2.7 KB
- 参考文档reference/standards.md2.0 KB
- 脚本scripts/release.py9.3 KB
- 脚本scripts/test_release.py8.1 KB
- 其他templates/COMPATIBILITY.md.tmpl1.1 KB
- 其他templates/CONTRACTS.md.tmpl1.3 KB
- 其他templates/release.config.json.tmpl517 B
03 SKILL.md 正文
Guidelines for Writing Rust Tests
Guidelines for writing new tests for Rust code.
Guidelines
- Test against the public API of the code under test.
- Test private APIs if and only if the private component is highly complex and difficult to test through the public API.
- Use
instawhenever you are testing output that is difficult to predict or compare. - Where appropriate, use
proptestto add property-based tests for key invariants. - Testing code should be written with the same care reserved to production code. Avoid unnecessary duplication, introduce helpers to reduce boilerplate and ensure readability. The intent of a test should be obvious or, if not possible, clearly documented.
- Do not reference exact line numbers in comments, as they may change over time.
Code organization
- Put tests under the
testsdirectory of the relevant crate if they don't rely on private APIs. - The
testsdirectory should be organized as a crate, with amain.rsfile and all tests in modules. Refer to thetrie_rs/testsdirectory as an example. - If the test must rely on private APIs, co-locate them with the code they test, using a
#[cfg(test)]module.
Dealing with extern C symbols
Check out CONTRIBUTING.md for instructions on how to deal with undefined C symbols in Rust tests.