rust-testing

Write and run Rust unit, integration, property, and async tests with proptest and mockall.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/luckyegg168/rust-skill --skill rust-testing-luckyegg168
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-testing
Source: https://github.com/luckyegg168/rust-skill/tree/main/rust-skills/rust-testing
Command: npx skills add https://github.com/luckyegg168/rust-skill --skill rust-testing-luckyegg168

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Rust developers often struggle with organizing test modules, mocking trait dependencies, generating edge-case inputs, and measuring code coverage. This Skill provides structured guidance for the full Rust testing workflow, from basic #[test] functions to property-based testing and CI-ready coverage reports. ## Core Features & Use Cases - Test Organization & Assertions: Covers #[cfg(test)] unit tests, tests/ directory integration tests, doc tests, assert! macro selection, #[should_panic], and Result<()> test patterns. - Mocking & Property Testing: Uses mockall to mock trait dependencies and proptest to automatically generate boundary-case inputs that verify code invariants. - Coverage & Fast Execution: Generates coverage reports with cargo-llvm-cov (with --fail-under-lines thresholds) and accelerates large test suites with cargo-nextest. - Use Case: When building a Rust service that depends on a database repository trait, use mockall to isolate the business logic, proptest to verify invariants like reverse involution, and cargo-llvm-cov to enforce an 80% line coverage gate in CI. ## Quick Start Ask the AI to write unit tests with mockall mocks and proptest property tests for your Rust crate, then set up cargo-llvm-cov coverage reporting.

Frequently Asked Questions about rust-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests in Rust?▼

Place a #[cfg(test)] mod tests block inside your source file and annotate each test function with #[test]. Use assert_eq! for equality checks and run them with cargo test. Unit tests can access private and pub(crate) items.

How to mock a trait in Rust with mockall?▼

Annotate the trait with #[automock] from mockall, which generates a MockXxx struct. In tests, configure expectations with expect_method(), .with(), .times(), and .returning() to control call counts and return values.

What is the difference between proptest and quickcheck in Rust?▼

Both are property-based testing libraries that generate random inputs to verify invariants. proptest offers richer strategy combinators, prop_compose! for custom strategies, and a more controlled shrinking mechanism for minimizing failing cases.

How do I measure Rust test coverage with cargo-llvm-cov?▼

Install llvm-tools-preview and cargo-llvm-cov, then run cargo llvm-cov for a text summary or cargo llvm-cov --html for a browsable report. Use --fail-under-lines 80 to enforce a minimum coverage threshold in CI.

Why does my async test fail with 'Cannot start a runtime from within a runtime'?▼

This error occurs when you manually create Runtime::new() inside a #[tokio::test] function, which already starts a runtime. Remove the manual runtime construction and use .await directly in the async test body.

When should I use integration tests instead of unit tests in Rust?▼

Use tests/ directory integration tests to verify public API end-to-end behavior, since each file compiles as a separate crate accessing only pub items. Use #[cfg(test)] unit tests when you need to test private functions or internal logic.