rust-testing-benchmarking
Skill4 starsChanged 4 months agoApache-2.0View on GitHub
Master Rust testing and benchmarking. Use when writing unit tests, integration tests, documentation tests, property-based tests with proptest, statistical benchmarking with Criterion.rs, or setting up test infrastructure.
In this repository80 other files it gives its agents.
- a11y-accessibility-designSkill
- agentic-ui-patternsSkill
- ai-native-ui-designSkill
- ai-ui-anti-patternsSkill
- ai-ui-heuristicsSkill
- calm-technology-uiSkill
- conversion-growth-designSkill
- cross-platform-designSkill
- dark-mode-designSkill
- data-visualizationSkill
- design-systemsSkill
- design-thinking-processSkill
- error-empty-statesSkill
- ethical-design-patternsSkill
- form-uxSkill
- information-architectureSkill
- interaction-design-patternsSkill
- internationalization-uiSkill
- mobile-touch-designSkill
- modal-classes-lifecycleSkill
- modal-container-imagesSkill
- modal-dicts-queuesSkill
- modal-endpointsSkill
- modal-fundamentalsSkill
- modal-gpu-computeSkill
- modal-networkingSkill
- modal-observabilitySkill
- modal-parallel-executionSkill
- modal-sandboxesSkill
- modal-scaling-performanceSkill
- modal-schedulingSkill
- modal-secretsSkill
- modal-serversSkill
- modal-storageSkill
- modal-web-servingSkill
- modal-workspace-adminSkill
- motion-design-principlesSkill
- notifications-permissionsSkill
- onboarding-uxSkill
- rust-api-designSkill
- rust-async-programmingSkill
- rust-cargo-masterySkill
- rust-cli-applicationsSkill
- rust-clippy-lintsSkill
- rust-closures-iteratorsSkill
- rust-compiler-internalsSkill
- rust-concurrencySkill
- rust-design-patternsSkill
- rust-editionsSkill
- rust-embeddedSkill
- rust-error-handlingSkill
- rust-game-developmentSkill
- rust-lifetimes-borrowingSkill
- rust-macrosSkill
- rust-performanceSkill
- rust-rustdocSkill
- rust-rustup-toolchainSkill
- rust-smart-pointersSkill
- rust-type-systemSkill
- rust-unsafe-ffiSkill
- The first 60 shown.
The file
Files
Rust Testing & Benchmarking
Comprehensive guide to testing and benchmarking in Rust.
When to Use This Skill
- Writing unit tests with #[test]
- Creating integration tests
- Writing documentation tests (doctests)
- Setting up property-based tests with proptest
- Benchmarking with Criterion.rs
- Testing async code
Test Organization
Unit Tests
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
#[test]
#[should_panic(expected = "divide by zero")]
fn test_panic() {
panic!("divide by zero");
}
#[test]
fn result_test() -> Result<(), String> {
if true {
Ok(())
} else {
Err("failed".to_string())
}
}
}Integration Tests
// tests/integration_test.rs
use my_crate::add;
#[test]
fn test_integration() {
assert_eq!(add(2, 2), 4);
}Doc Tests
/// Adds two numbers.
///
/// # Examples
///
/// ```
/// assert_eq!(add(2, 2), 4);
/// ```
pub fn add(a: i32, b: i32) -> i32 {
a + b
}Run with: cargo test --doc
Property-Based Testing with proptest
Setup
[dev-dependencies]
proptest = "1.0"Basic Usage
use proptest::prelude::*;
proptest! {
#[test]
fn test_addition(a in 0..1000i32, b in 0..1000i32) {
assert!(a + b >= a);
assert!(a + b >= b);
}
}Custom Strategies
use proptest::strategy::Strategy;
fn non_empty_string() -> impl Strategy<Value = String> {
"[a-z]{1,100}"
}
proptest! {
#[test]
fn test_string(s in non_empty_string()) {
assert!(!s.is_empty());
}
}Benchmarking with Criterion.rs
Setup
[dev-dependencies]
criterion = "0.5"
[[bench]]
name = "my_benchmark"
harness = falseBasic Benchmark
use criterion::{black_box, criterion_group, criterion_main, Criterion};
fn fibonacci(n: u64) -> u64 {
match n {
0 => 0,
1 => 1,
_ => fibonacci(n - 1) + fibonacci(n - 2),
}
}
fn bench_fibonacci(c: &mut Criterion) {
c.bench_function("fibonacci 20", |b| {
b.iter(|| fibonacci(black_box(20)))
});
}
criterion_group!(benches, bench_fibonacci);
criterion_main!(benches);Run with: cargo bench
Benchmark with Inputs
fn bench_vec_sort(c: &mut Criterion) {
let mut group = c.benchmark_group("sort");
for size in [100, 1000, 10000].iter() {
let mut vec: Vec<i32> = (0..*size).collect();
group.bench_with_input(format!("{}", size), &size, |b, &s| {
b.iter(|| {
let mut v = vec.clone();
v.sort();
})
});
}
group.finish();
}Async Benchmarks
fn bench_async(c: &mut Criterion) {
let rt = tokio::runtime::Runtime::new().unwrap();
c.bench_function("async_task", |b| {
b.to_async(&rt).iter(|| async {
some_async_function().await
})
});
}Reference Map
references/unit-tests.md- Unit test patternsreferences/integration-tests.md- Integration test setupreferences/property-testing.md- proptest strategiesreferences/benchmarking.md- Criterion.rs setup
Key Commands
cargo test
cargo test --test integration_test
cargo test --doc
cargo bench
cargo test --releaseKey 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.

