rust-testing
Skill1 starsChanged 5 days agoMITView on GitHub
Design, implement, and validate Rust tests, including unit, integration, doctest, compile-fail, property, fuzz, benchmark, coverage, async, concurrency, process, daemon, IPC, terminal, platform, and hardware-facing test strategies. Use when users ask for Rust test architecture, flaky-test diagnosis, coverage gates, benchmarks, trybuild, cargo-nextest, real-process tests, or failure-path verification.
- Installs packages
44 other projects use a version of this, 1 of them edited.
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-errors, rust-security and 6 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.
dawidpereiraSkillrust-errors
Rust error handling patterns with Result, Option, thiserror, and anyhow. Use whenever implementing error types, adding error propagation with ?, choosing between panic and Result, or working with .unwrap()/.expect(). Covers library vs application error strategy, error chaining, context, and custom error types. Also use when seeing unwrap abuse or unclear error propagation in code review.
Also in 4 projects that use this
adxptivedSkillrust-security
Rust application security, supply-chain hardening, cryptography hygiene, secrets handling, and secure service patterns. Use when: - User asks about secure Rust code, threat modeling, auth, tokens, password hashing, or secrets - User uses crates like argon2, password-hash, ring, rustls, secrecy, zeroize, jsonwebtoken, or biscuit - User handles untrusted input, file paths, uploads, subprocesses, deserialization, or SSRF-prone URLs - User wants cargo audit, cargo deny, dependency policy, SBOMs, or supply-chain checks - User writes unsafe code exposed to untrusted data or FFI boundaries - User builds web APIs that need TLS, CORS, cookies, sessions, CSRF, rate limits, or tenant isolation - User implements OAuth2/OIDC, API key validation, JWT verification, or mTLS
Also in 3 projects that use this
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
dawidpereiraSkillrust-macros
Rust macros — macro_rules!, proc macros, derive macros, attribute macros, fragment specifiers, repetition, hygiene, cargo expand, when to use macros vs generics. Use when writing or debugging declarative or procedural macros, choosing between macros and other abstractions, understanding expansion errors, or generating repetitive code.
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
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
Other versions44 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- full-stack-skills/rust-skills★ 891% same
Wrote their own version · 43
- 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
- gongyijie85/dsh-ecc★ 8same name
- FimawLLC/fimaw-skills★ 3same name
- aayushsoam/clawbot-plus★ 2same name
- aphrody-code/bxc★ 2same name
33 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 repository16 other files it gives its agents.
- accessibilitySkill
- cargo-fuzzSkill
- core-web-vitalsSkill
- impeccableSkill
- property-based-testingSkill
- rust-best-practicesSkill
- rust-cargo-buildSkill
- rust-cliSkill
- rust-concurrencySkill
- rust-databaseSkill
- rust-http-clientSkill
- rust-performanceSkill
- rust-web-securitySkill
- rust-webSkill
- sonjoo-auditSkill
- sonjoo-auditSkill
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 43 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 20
Test attributes (#[should_panic], #[ignore], #[cfg(test)])
- Very specific: line 193
Write unit tests — Implement #[test] functions within #[cfg(test)] modules
- Distinctive: line 194
Add integration tests — Create independent crate-type files in the tests/ directory
- Distinctive: line 195
Add documentation tests — Embed executable code blocks inside /// comments
- Very specific: line 196
Run and debug — Use cargo test.
“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 and Benchmarking
Based on Chapter 11 of The Rust Programming Language and the Rust Book.
Capability Boundaries
✅ Strengths
- Unit tests (using
#[test], organizing test modules with#[cfg(test)]) - Assertion macros (
assert!,assert_eq!,assert_ne!,debug_assert!) - Test attributes (
#[should_panic],#[ignore],#[cfg(test)]) - Integration tests (tests/ directory and shared modules)
- Documentation tests (code blocks, hidden lines with
#, should_panic/no_run/ignore flags) - cargo test runner (filtering, --nocapture, --test-threads, --include-ignored options)
- Stable Criterion benchmarks; explicitly distinguishing stable Criterion from nightly-only libtest
#[bench]attribute - Code coverage using cargo-llvm-cov
- Asynchronous race conditions, backpressure, timeouts, process/daemon models, platform matrices, and resource-constrained testing
⚠️ Prerequisites
- Understanding the Rust module system
❌ Out of Scope
- Property-based tests (
proptest) → property-based-testing - Mock objects → Not currently covered
- Basic Rust syntax → Consult The Rust Book
When to Use
- "Write unit tests"
- "Where should integration tests be placed?"
- "How do I write documentation tests?"
- "Performance benchmarking"
- "Check code coverage"
Routing Boundary
For Sonjoo rule tests, follow the lab fixture and coverage contract and the fixture guide. Derive expected outcomes from the rule contract and fixture, independently of the implementation. Choose the existing context, HTTP, crawl, or Chromium harness that matches the required evidence. Use property-based-testing for invariants and cargo-fuzz for fuzz harnesses.
Unit Tests
// src/lib.rs
pub fn add(a: i32, b: i32) -> i32 { a + b }
pub fn divide(a: i32, b: i32) -> i32 {
if b == 0 { panic!("divide by zero"); }
a / b
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add() {
assert_eq!(add(2, 2), 4);
}
#[test]
fn test_add_negative() {
assert_eq!(add(-1, 1), 0, "addition with negative");
}
#[test]
#[should_panic(expected = "divide by zero")]
fn test_divide_by_zero() {
divide(1, 0);
}
#[test]
#[ignore = "not implemented"]
fn test_future() { unimplemented!() }
}Integration Tests
my-project/
├── Cargo.toml
├── src/lib.rs
└── tests/
├── common/ # Test shared modules
│ └── mod.rs
├── integration_test.rs
└── api_test.rs// tests/integration_test.rs — Each file is an independent crate
use my_project::add;
#[test]
fn integration_test() {
assert_eq!(add(1, 2), 3);
}
// tests/common/mod.rs — Shared helper functions
pub fn setup() { /* ... */ }Documentation Tests (doctest)
/// Add two numbers.
///
/// ```
/// use my_crate::add;
/// assert_eq!(add(2, 3), 5);
/// ```
///
/// ```rust,should_panic
/// my_crate::divide(1, 0);
/// ```
///
/// ```rust,no_run
/// // Compile but do not run
/// loop {}
/// ```
pub fn add(a: i32, b: i32) -> i32 { a + b }cargo test Commands
cargo test # Run all tests
cargo test test_name # Filter by name
cargo test -- --nocapture # Show println output
cargo test -- --test-threads=1 # Single thread
cargo test -- --skip test_name # Skip specific tests
cargo test -- --ignored # Only run #[ignore] tests
cargo test -- --include-ignored # Include ignored tests
cargo test --doc # Run only documentation tests
cargo test -p my-crate # Specific packageBenchmarks
Stable projects should prioritize Criterion. The built-in libtest #[bench] still relies on nightly's #![feature(test)], which cannot be used as a stable default solution.
// Nightly-only builtin approach (do not use for stable gatekeeping)
#![feature(test)]
extern crate test;
#[cfg(test)]
mod benches {
use test::Bencher;
use super::*;
#[bench]
fn bench_add(b: &mut Bencher) {
b.iter(|| add(1, 2));
}
}
// Stable approach using criterion
// [dev-dependencies] criterion = { version = "0.5", features = ["html_reports"] }
use criterion::{black_box, Criterion};
fn bench_add(c: &mut Criterion) {
c.bench_function("add", |b| b.iter(|| add(black_box(1), black_box(2))));
}
criterion_group!(benches, bench_add);
criterion_main!(benches);Code Coverage
# Install
cargo install cargo-llvm-cov
# Usage
cargo llvm-cov # Run and report results
cargo llvm-cov --open # Generate HTML reports
cargo llvm-cov --lcov --output-path lcov.info # LCOV format outputWorkflow
- Prepare test environment — Ensure cargo test is available, confirm test types (unit/integration/documentation)
- Write unit tests — Implement #[test] functions within
#[cfg(test)]modules - Add integration tests — Create independent crate-type files in the tests/ directory
- Add documentation tests — Embed executable code blocks inside /// comments
- Run and debug — Use cargo test; use --nocapture to locate issues; prioritize resource isolation or test grouping for shared resources, avoiding permanent serialization of full test suites
- Concurrency and platform validation — Implement bounded assertions for queue limits, slow consumers, disconnections, cancellations, timeouts, and graceful shutdowns on real target platforms; run platform-specific code directly
- Coverage checks — Use cargo llvm-cov to verify coverage ranges
Gotchas
- Code in
#[cfg(test)]modules does not compile into release builds — Helper functions should reside in tests/common/mod.rs - Integration test files are independent crates — Cannot use super:: or crate:: prefixes within them
- Hidden lines (#) in documentation tests remain executable but invisible to the compiler
- cargo test runs by default in parallel; shared resource conflicts should be resolved via unique temporary directories/ports, process isolation, nextest test group limits, or local serialization only when necessary
- #[bench] requires #![feature(test)] — Stable Rust must use criterion instead
- Providing a broad timeout for async tests hides deadlock causes; also assert intermediate states, task recovery, and resource counts
On-Demand Resources
- Test examples
- Macro commands and command reference
- Concurrency, daemon, and platform testing: Test for memory leaks in tasks, slow consumers, race conditions, real processes, and resource-limited parallelism when reading.
examples/golden-tests/: CI compilation and execution of doctest golden examples
Official References
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.

