Rust Testing Patterns
A TDD-driven reference for writing Rust unit, integration, async, property-based and mocked tests with coverage targets.
Dev & CodingIntermediate★ 497⑂ 55AI score 9/10Last updated: Nov 24, 2026
What it does
- Walks Claude through the RED → GREEN → REFACTOR cycle in Rust, using
todo!()placeholders to start from a failing test. - Provides concrete patterns for
#[cfg(test)]unit tests,tests/integration binaries, and#[tokio::test]async tests including timeouts. - Covers
rstest(parameterized cases and fixtures),proptest(roundtrip properties, custom strategies),mockall(trait mocking with expectations), andcriterionbenchmarks. - Adds coverage workflow with
cargo llvm-cov, per-code-type targets (100% critical logic, 90%+ public API, 80%+ general), and a GitHub Actions job. - Includes a practical DO/DON'T list: no
sleep()in tests, preferassert_eq!, never skip error paths.
Who it's for
- Rust developers raising test coverage on libraries or services.
- Engineers adopting TDD and wanting a concrete Rust playbook.
- Teams testing tokio-based async code or dependency-heavy service layers.
- Teams enforcing coverage gates in CI.
Examples
- "Add TDD tests for
parse_config, including error variants" → a failing test is written first, then a minimal implementation. - "Mock the
UserRepositorytrait with mockall to test the service layer" → generates#[automock]plusexpect_find_by_id().with(eq(42))expectations. - "Verify encode/decode roundtrip with proptest and fail CI under 80% coverage" → produces a
proptest!block andcargo llvm-cov --fail-under-lines 80step.
· · · Install guide · · ·
Try it now, no install
Paste this into Claude to use the skill without installing anything.
Read the instructions in this file and follow them to help me: https://raw.githubusercontent.com/aiskillstore/marketplace/HEAD/pending/affaan-m/rust-testing/SKILL.md What I want: (describe your task here)
If Claude can't open the link, open it yourself and paste the contents instead.
↓ If it works for you, download the ZIP below and install it. Then it runs on its own — no pasting each time.
Install in the Claude app (no terminal)
- Download the ZIP with the button below.
- In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
- Go to Customize → Skills → + → 'Upload a skill' and upload the ZIP.
Install in Claude Code
Let Claude do it — paste this into Claude Code
Install the skill I found on AI Skill Mart. Copy the pending/affaan-m/rust-testing folder from the GitHub repo aiskillstore/marketplace into my ~/.claude/skills/rust-testing/. When it's done, tell me in one line what this skill can do.
Install with a command instead
git clone https://github.com/aiskillstore/marketplace.git /tmp/aiskillstore && mkdir -p ~/.claude/skills/rust-testing && cp -r /tmp/aiskillstore/pending/affaan-m/rust-testing/* ~/.claude/skills/rust-testing/⚠ This is a third-party skill. Check the source repository before installing.
- Open a terminal.
- Clone the marketplace repo:
git clone https://github.com/aiskillstore/marketplace.git /tmp/aiskillstore - Create the skill folder:
mkdir -p ~/.claude/skills/rust-testing - Copy the files:
cp -r /tmp/aiskillstore/pending/affaan-m/rust-testing/* ~/.claude/skills/rust-testing/ - Restart Claude Code and confirm
rust-testingappears in your skill list. - In any Rust project, ask something like "write tests for this module" to trigger the skill.
- Prepare the tooling: run
cargo install cargo-llvm-covand addrstest,proptest,mockall, andcriterionto[dev-dependencies]in Cargo.toml.