
Rust Testing
Run RED-GREEN-REFACTOR TDD in Rust with mocks, async tests, proptest, and llvm-cov toward strong coverage on new crates.
Overview
Rust Testing is an agent skill most often used in Ship (also Build) that teaches TDD, mocking, async and property-based tests, and llvm-cov coverage discipline in Rust.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill rust-testingWhat is this skill?
- 7-step TDD loop: identify target, write test, mock, RED, GREEN, refactor, coverage check
- RED-GREEN-REFACTOR cycle with todo!() placeholders for failing-first tests
- mockall for dependency isolation; rstest and proptest for parameterized and property-based cases
- Async testing patterns for Tokio-style code
- Coverage via cargo-llvm-cov with 80%+ target
- 7-step how-it-works flow from identify target through coverage check
- Documented RED-GREEN-REFACTOR cycle with explicit REPEAT
- Coverage target 80%+ via cargo-llvm-cov
Adoption & trust: 4.5k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your Rust crate grows without a consistent TDD habit, so regressions slip through and coverage stays unknown.
Who is it for?
Indie Rust developers who want agent-guided TDD on new modules or backfilling tests on existing crates.
Skip if: Teams that only want one-off snapshot tests with no mocking strategy or no appetite for property-based testing overhead.
When should I use this skill?
Writing new Rust functions, methods, or traits; adding test coverage; creating benchmarks; implementing property-based tests; following TDD in Rust projects.
What do I get? / Deliverables
You maintain a RED-GREEN-REFACTOR loop with mockall, rstest/proptest where needed, and measured coverage before you ship changes.
- #[test] and integration test modules following TDD order
- Mocked unit tests isolating dependencies
- Coverage report and benchmark stubs where performance matters
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Primary shelf is Ship/testing because the skill optimizes verification gates, coverage targets, and TDD discipline before release. Testing subphase matches unit/integration/async patterns, mockall isolation, property tests, and the documented cargo-llvm-cov 80%+ goal.
Where it fits
Agent writes a failing #[test] with todo!() before implementing a new parser function.
You add integration tests and run cargo-llvm-cov before tagging a release.
Benchmarks are added for a hot loop after unit tests stay green.
rstest tables cover edge cases on a public API enum.
How it compares
Procedural TDD workflow for Rust—not a language tutorial that skips test design and coverage tooling.
Common Questions / FAQ
Who is rust-testing for?
Solo and indie builders shipping Rust CLIs, services, or libraries who want structured tests, mocks, and coverage targets while coding with agents.
When should I use rust-testing?
In Build while implementing functions and traits; in Ship before release when adding integration tests, async coverage, benchmarks, or llvm-cov gates on critical paths.
Is rust-testing safe to install?
Check the Security Audits panel on this Prism page; the skill suggests running cargo test and coverage tools locally—review what your agent is allowed to execute.
SKILL.md
READMESKILL.md - Rust Testing
# Rust Testing Patterns Comprehensive Rust testing patterns for writing reliable, maintainable tests following TDD methodology. ## When to Use - Writing new Rust functions, methods, or traits - Adding test coverage to existing code - Creating benchmarks for performance-critical code - Implementing property-based tests for input validation - Following TDD workflow in Rust projects ## How It Works 1. **Identify target code** — Find the function, trait, or module to test 2. **Write a test** — Use `#[test]` in a `#[cfg(test)]` module, rstest for parameterized tests, or proptest for property-based tests 3. **Mock dependencies** — Use mockall to isolate the unit under test 4. **Run tests (RED)** — Verify the test fails with the expected error 5. **Implement (GREEN)** — Write minimal code to pass 6. **Refactor** — Improve while keeping tests green 7. **Check coverage** — Use cargo-llvm-cov, target 80%+ ## TDD Workflow for Rust ### The RED-GREEN-REFACTOR Cycle ``` RED → Write a failing test first GREEN → Write minimal code to pass the test REFACTOR → Improve code while keeping tests green REPEAT → Continue with next requirement ``` ### Step-by-Step TDD in Rust ```rust // RED: Write test first, use todo!() as placeholder pub fn add(a: i32, b: i32) -> i32 { todo!() } #[cfg(test)] mod tests { use super::*; #[test] fn test_add() { assert_eq!(add(2, 3), 5); } } // cargo test → panics at 'not yet implemented' ``` ```rust // GREEN: Replace todo!() with minimal implementation pub fn add(a: i32, b: i32) -> i32 { a + b } // cargo test → PASS, then REFACTOR while keeping tests green ``` ## Unit Tests ### Module-Level Test Organization ```rust // src/user.rs pub struct User { pub name: String, pub email: String, } impl User { pub fn new(name: impl Into<String>, email: impl Into<String>) -> Result<Self, String> { let email = email.into(); if !email.contains('@') { return Err(format!("invalid email: {email}")); } Ok(Self { name: name.into(), email }) } pub fn display_name(&self) -> &str { &self.name } } #[cfg(test)] mod tests { use super::*; #[test] fn creates_user_with_valid_email() { let user = User::new("Alice", "alice@example.com").unwrap(); assert_eq!(user.display_name(), "Alice"); assert_eq!(user.email, "alice@example.com"); } #[test] fn rejects_invalid_email() { let result = User::new("Bob", "not-an-email"); assert!(result.is_err()); assert!(result.unwrap_err().contains("invalid email")); } } ``` ### Assertion Macros ```rust assert_eq!(2 + 2, 4); // Equality assert_ne!(2 + 2, 5); // Inequality assert!(vec![1, 2, 3].contains(&2)); // Boolean assert_eq!(value, 42, "expected 42 but got {value}"); // Custom message assert!((0.1_f64 + 0.2 - 0.3).abs() < f64::EPSILON); // Float comparison ``` ## Error and Panic Testing ### Testing `Result` Returns ```rust #[test] fn parse_returns_error_for_invalid_input() { let result = parse_config("}{invalid"); assert!(result.is_err()); // Assert specific error variant let err = result.unwrap_err(); assert!(matches!(err, ConfigError::ParseError(_))); } #[test] fn parse_succeeds_for_valid_input() -> Result<(), Box<dyn std::error::Error>> { let config = parse_config(r#"{"port": 8080}"#)?; assert_eq!(config.port, 8080); Ok(()) // Test fails if any ? returns Err } ``` ### Testing Panics ```rust #[test] #[should_panic] fn panics_on_empty_input() { process(&[]); } #[test] #[should_panic(expected = "index out of bounds")] fn panics_with_specific_message() { let v: Vec<i32> = vec![]; let