rust-testing

Write Rust unit, integration, async, and property-based tests following TDD methodology.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill rust-testing-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-testing
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/rust-testing
Command: npx skills add https://github.com/ibytechaos/claude --skill rust-testing-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Rust developers often struggle to structure comprehensive test suites that cover unit logic, async code, error paths, and edge cases while maintaining high coverage. This Skill provides concrete patterns for every testing scenario in the Rust ecosystem, eliminating guesswork about which crates and idioms to use. ## Core Features & Use Cases - Full Testing Stack Patterns: Covers unit tests with #[cfg(test)] modules, integration tests in tests/, async tests with tokio::test, doc tests, and Criterion benchmarks. - TDD Workflow Guidance: Walks through the RED-GREEN-REFACTOR cycle with concrete Rust examples, including using todo!() as a placeholder for failing-first tests. - Advanced Techniques: Demonstrates property-based testing with proptest, parameterized tests with rstest, and trait-based mocking with mockall. - Use Case: When adding a new feature to a Rust service, use this Skill to write a failing parameterized test with rstest, mock the repository layer with mockall, implement the feature, then verify 80%+ coverage with cargo-llvm-cov. ## Quick Start Ask the assistant to write tests for a Rust function or module following TDD, and it will produce the appropriate unit, integration, or property-based test code.

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)] module with #[test] functions in the same file as your code, using use super::* to access private items. Run them with cargo test, and prefer assert_eq! over assert! for clearer failure messages.

How to test async Rust code with tokio?

Use the #[tokio::test] attribute instead of #[test] to run async test functions. You can test timeouts by wrapping operations in tokio::time::timeout and asserting the result is an error.

proptest vs rstest for Rust testing?

rstest provides parameterized tests and fixtures for known input cases, while proptest generates random inputs to verify properties like roundtrip encoding or sort invariants. Use rstest for concrete scenarios and proptest for edge-case discovery.

How do I mock traits in Rust tests?

Use the mockall crate with #[automock] on your trait to generate a mock implementation. Configure expectations with methods like expect_find_by_id().with(eq(42)).times(1).returning(...) to control behavior and verify call counts.

How to measure Rust test coverage?

Install cargo-llvm-cov and run cargo llvm-cov for a summary, --html for a report, or --fail-under-lines 80 to enforce a threshold in CI. Target 100% for critical logic, 90%+ for public APIs, and 80%+ for general code.

When should I avoid #[should_panic] in Rust tests?

Avoid #[should_panic] when the function returns a Result, since testing Result::is_err() gives more precise assertions on specific error variants. Reserve should_panic for genuine panic conditions, ideally with an expected message.