rust-tests-guidelines
Follow best practices for writing maintainable and robust Rust tests for public and private APIs.
Install
mkdir -p .claude/skills/rust-tests-guidelines && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1061" && unzip -o skill.zip -d .claude/skills/rust-tests-guidelines && rm skill.zipInstalls to .claude/skills/rust-tests-guidelines
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Guidelines for writing Rust tests. Use this when you want to write Rust tests.Key capabilities
- →Test against public APIs
- →Implement snapshot testing with insta
- →Add property-based tests with proptest
- →Co-locate private API tests in cfg(test) modules
How it works
It organizes tests into a dedicated tests directory for public APIs and uses conditional compilation for private API testing. It mandates the use of specialized crates for complex output comparisons and invariant testing.
Inputs & outputs
When to use rust-tests-guidelines
- →Writing unit tests for Rust public APIs
- →Setting up property-based tests
- →Implementing snapshot testing for complex output
- →Structuring test suites for crates
About this skill
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 for public (
pub) items under the crate'stestsdirectory. Two layouts are in use and both are fine — match whichever the crate already has:tests/integration/— one test crate with its ownmain.rsand a module per area (trie_rs,geo,query_eval, …). Prefer this for a new crate: it compiles as a single unit instead of one binary per file.- Cargo's default layout — one integration binary per
tests/*.rsfile (varint,fork_gc,rlookup, …).
- If the test must rely on private APIs, co-locate it with the code it tests, using a
#[cfg(test)]module. Integration tests cannot reachpub(crate)or private items, so this is the only option for them — but prefer exercising the behavior through the public API where you can, per guideline 2 above.
Dealing with extern C symbols
Check out CONTRIBUTING.md for instructions on how to deal with undefined C symbols in Rust tests.
When not to use it
- →When testing private APIs that are simple enough to cover via public interfaces
Limitations
- →Requires specific handling for undefined C symbols
- →Avoids referencing exact line numbers in comments
How it compares
It enforces a strict separation between public API testing and internal implementation testing compared to standard ad-hoc testing.
Compared to similar skills
rust-tests-guidelines side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| rust-tests-guidelines (this skill) | 7 | 5mo | No flags | Beginner |
| check-rust-coverage | 5 | 5mo | Review | Beginner |
| check-code-quality | 1 | 29d | Review | Advanced |
| lint | 1 | 2mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by RediSearch
View all by RediSearch →You might also like
check-rust-coverage
RediSearch
Check which Rust lines are not covered by Rust tests.
check-code-quality
r3bl-org
Run comprehensive Rust code quality checks including compilation, linting, documentation, and tests. Use after completing code changes and before creating commits.
lint
RediSearch
Check code quality and formatting before committing changes
run-clippy
r3bl-org
Run clippy linting, enforce comment punctuation rules, format code with cargo fmt, and verify module organization patterns. Use after code changes and before creating commits.
move-code-quality
davila7
Analyzes Move language packages against the official Move Book Code Quality Checklist. Use this skill when reviewing Move code, checking Move 2024 Edition compliance, or analyzing Move packages for best practices. Activates automatically when working with .move files or Move.toml manifests.
pre_commit
pums974
Standardized pre-commit workflow for linting, formatting, and local quality gates.