Rust Tests Guidelines
Testing & Qualityrust-tests-guidelinesRust Tests Guidelines is an Agent Skill for testing & quality published in the RediSearch/RediSearch repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Guidelines for writing Rust tests. Use this when you want to write Rust tests.
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/RediSearch/RediSearch/blob/HEAD/.skills/rust-tests-guidelines/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/rust-tests-guidelines, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
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.