rust-testing
Skill1 starsChanged 40 days agoMITView on GitHub
Rust testing — unit, integration, async, table-driven (rstest), property-based (proptest), fuzzing (cargo-fuzz), mutation (cargo-mutants, over the crate or only a change's diff with --in-diff), mocking (mockall), snapshot (insta), doc tests, and coverage. Use when writing or reviewing Rust tests, adding coverage, choosing a testing crate, or setting up CI. Triggers: #[tokio::test], rstest, proptest, cargo-fuzz, cargo-mutants, mutants on the diff, --in-diff, mockall, insta, nextest.
44 other projects use a version of this.
Adopted by
Most recently taken up by
- KevinLoichot/everything-claude-codetheir own version, first seen Nov 29, 2026
- aayushsoam/clawbot-plustheir own version, first seen Nov 29, 2026
- multiplex-ai/muggle-ai-teamstheir own version, first seen Nov 29, 2026
- rewrite-rs/skillstheir own version, first seen Nov 29, 2026
- Dankosik/cargo-modernizetheir own version, first seen Nov 29, 2026
- satvikgbusiness-jpg/Claude-skillstheir own version, first seen Nov 29, 2026
Used with
Projects with it also use rust-api-design, rust-async-patterns and 4 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
adxptivedSkillrust-api-design
Rust API Design guidelines, naming conventions, and best practices. Use when: - User is designing a library, crate, or public APIs - Implementing patterns like Builder, Typestate, or Extension traits - Designing public structures, enums, or traits - Working with common traits (From/Into, Default, AsRef, Debug, Clone) - Applying #[must_use] or #[non_exhaustive] attributes - Restricting trait implementation via Sealed Traits - Formatting naming structures and lifetime designs
Also in 3 projects that use this
klauswgSkillrust-async-patterns
Master Rust async programming with Tokio, async traits, error handling, and concurrent patterns. Use when building async Rust applications, implementing concurrent systems, or debugging async code.
Also in 5 projects that use this
MicrosoftSkillrust-best-practices
Guide for writing idiomatic Rust code based on Apollo GraphQL's best practices handbook. Use this skill when: (1) writing new Rust code or functions, (2) reviewing or refactoring existing Rust code, (3) deciding between borrowing vs cloning or ownership patterns, (4) implementing error handling with Result types, (5) optimizing Rust code for performance, (6) writing tests or documentation for Rust projects.
Also in 9 projects that use this
junimnjwSkillrust-patterns
Idiomatic Rust patterns, ownership, error handling, traits, concurrency, and best practices for building safe, performant applications.
Also in 4 projects that use this
GoogleSkillimprove-codebase-architecture
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
Also in 3 projects that use this
GoogleSkillgrill-me
A relentless interview to sharpen a plan or design.
Also in 3 projects that use this
Other versions44 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 44
- loulanyue/awesome-claude-notes★ 272same name
- Blushyes/reef★ 84same name
- Fmarzochi/EGC★ 61same name
- huiali/rust-skills★ 47same name
- rewrite-rs/skills★ 32same name
- Bitslix/BLXCode★ 15same name
- full-stack-skills/rust-skills★ 8same name
- gongyijie85/dsh-ecc★ 8same name
- FimawLLC/fimaw-skills★ 3same name
- aayushsoam/clawbot-plus★ 2same name
34 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository42 other files it gives its agents.
- AGENTS.mdAGENTS.md
- addressing-findingsSkill
- auditSkill
- codebase-onboardingSkill
- codex-reviewSkill
- compatibilitySkill
- debuggingSkill
- developSkill
- distributed-racesSkill
- memorySkill
- nix-dev-envSkill
- nix-flakesSkill
- nixosSkill
- nix-packagingSkill
- nix-reviewSkill
- refactoringSkill
- retroSkill
- review-initSkill
- review-rulesSkill
- rust-architecture-reviewSkill
- rust-architectureSkill
- rust-cliSkill
- rust-cloud-nativeSkill
- rust-concurrencySkill
- rust-ecosystemSkill
- rust-embeddedSkill
- rust-errorsSkill
- rust-fintechSkill
- rust-idiomsSkill
- rust-macrosSkill
- rust-mlSkill
- rust-navigationSkill
- rust-ownershipSkill
- rust-performanceSkill
- rust-pluginsSkill
- rust-reviewSkill
- rust-securitySkill
- rust-traitsSkill
- rust-unsafeSkill
- rust-webSkill
- specsSkill
- sql-reviewSkill
The file
We split this skill into the rules it gives an agent
6 rules. 1 is common, 0 are distinctive, and 5 are very specific to this project.
1
Common
Most of the 43 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Common: line 91
Test behavior, not implementation details.
- Very specific: line 92
Prefer assert_eq! over assert!(a == b) — better failure messages.
- Very specific: line 94
Put unit tests in a #[cfg(test)] mod tests next to the code.
- Very specific: line 98
Use #[should_panic] when you could assert result.is_err() (panic tests can pass for the wrong reason).
- Very specific: line 100
Use thread::sleep to "wait" in async tests — use tokio::time::pause/advance or channels.
- Very specific: line 112
Test crates are [dev-dependencies] — they never ship in the final binary.
“Common” is measured: kept by at least 6 in 10 of the 43 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust Testing
Self-contained guide to testing Rust: what to reach for, the TDD loop in Rust terms, and the commands. Deep examples live in the sub-files below — read the one you need, not all three.
When to Use
- Writing tests for new functions, methods, traits, or modules
- Adding coverage to existing code
- Choosing the right testing crate for a case (table-driven, property, mock, snapshot)
- Setting up the test runner and CI for a Rust project
Pick the right tool
| Situation | Reach for | Where |
| One behavior, one input | plain #[test] | core.md |
Function returns Result / can panic | ? in test / #[should_panic] | core.md |
| Cross-crate / public API behavior | integration test in tests/ | core.md |
| Show usage in the docs | doc test (``` in ///) | core.md |
| Same logic, many input/output pairs | rstest #[case] | advanced.md |
| Shared setup across tests | rstest #[fixture] | advanced.md |
async fn under test | #[tokio::test] | advanced.md |
| Invariant must hold for all inputs | proptest | advanced.md |
| Isolate a unit from a trait dependency | mockall | advanced.md |
Behavior spec in Given/When/Then (or Gherkin .feature) | plain test, or cucumber | advanced.md |
| Assert on large/structured output | insta snapshot | tooling.md |
| Faster runs, better output, CI | cargo nextest | tooling.md |
| Prove what's tested | cargo llvm-cov | tooling.md |
Find crashes/panics on adversarial bytes (parser, untrusted input, unsafe) | cargo-fuzz | advanced.md |
| Check tests actually catch bugs, not just run | cargo-mutants | tooling.md |
| Check a change's tests catch its own breakage | cargo mutants --in-diff <diff file> | tooling.md |
Benchmarking (
criterion,cargo bench) is not testing — it belongs torust-performance, not here.
The TDD loop in Rust
Discipline is RED → GREEN → REFACTOR. In Rust the mechanics are:
// RED — write the test first; stub the impl with todo!() so it compiles but fails
pub fn slugify(s: &str) -> String { todo!() }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn lowercases_and_dashes() {
assert_eq!(slugify("Hello World"), "hello-world");
}
}
// `cargo test` → panics at "not yet implemented" = RED// GREEN — minimal code to pass
pub fn slugify(s: &str) -> String {
s.to_lowercase().replace(' ', "-")
}
// `cargo test` → PASS. Now REFACTOR with the test as a safety net.Rules that keep the loop honest:
- Watch the test fail first — a test that was never red proves nothing.
- One behavior per test; the name states the scenario (
rejects_empty_input, nottest1). - Tests must be independent — no shared mutable state, no ordering assumptions.
Command cheatsheet
cargo test # all tests (unit + integration + doc)
cargo test name_substring # only tests whose name matches
cargo test -- --nocapture # show println!/dbg! output
cargo test --lib # unit tests only
cargo test --test api # one integration binary (tests/api.rs)
cargo test --doc # doc tests only
cargo test -- --include-ignored # also run #[ignore] tests
cargo test --no-fail-fast # don't stop at first failure(For cargo nextest and coverage, see tooling.md.)
DO / DON'T
DO
- Test behavior, not implementation details.
- Prefer
assert_eq!overassert!(a == b)— better failure messages. - Return
Resultfrom tests and use?instead of unwrapping each step. - Put unit tests in a
#[cfg(test)] mod testsnext to the code; integration tests intests/. - Quarantine or fix flaky tests immediately — never
#[ignore]and forget.
DON'T
- Use
#[should_panic]when you could assertresult.is_err()(panic tests can pass for the wrong reason). - Mock everything — prefer a real or in-memory implementation when feasible; mock only at true boundaries.
- Use
thread::sleepto "wait" in async tests — usetokio::time::pause/advanceor channels. - Assert on debug-formatted blobs by hand when a snapshot (
insta) is clearer.
Project defaults
This collection targets the latest stable toolchain:
[package]
edition = "2024"Test crates are [dev-dependencies] — they never ship in the final binary.
Boundaries
This skill covers writing and running Rust tests. Adjacent concerns belong elsewhere:
- Benchmarking and profiling (
criterion,cargo bench, flamegraphs) →rust-performance. - Fake-port unit tests and hexagonal adapter layering (what to fake vs. integrate) →
rust-architecture. - Deriving BDD scenarios from requirements →
specs. - Reporting and owning skipped-test status (don't let "no Docker" pass as "covered").
- Flagging weak or missing tests in a diff →
rust-review.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

