rust-testing

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

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

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 proven testing patterns and a TDD workflow so tests are written first, remain maintainable, and catch regressions early. ## Core Features & Use Cases - Full Testing Spectrum: Patterns for unit tests with #[cfg(test)] modules, integration tests in tests/, async tests with #[tokio::test], doc tests, and Criterion benchmarks. - Advanced Techniques: Parameterized tests with rstest, property-based testing with proptest, and trait-based mocking with mockall to isolate units under test. - Coverage & CI Integration: Commands for cargo-llvm-cov with an 80%+ line target and a ready GitHub Actions pipeline running fmt, clippy, tests, and coverage gates. - Use Case: When adding a new User::new validation function, write a failing test first (RED), implement the minimal code to pass (GREEN), refactor safely, then verify coverage meets the threshold before merging. ## Quick Start Ask the AI to write TDD-style tests for a Rust function, including unit tests, error cases, and mocks for its trait dependencies.

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 inside the same source file and mark test functions with `#[test]`. Use assertion macros like `assert_eq!` and `assert!`, then run them with `cargo test`.

How to test async Rust code with Tokio?▼

Use the `#[tokio::test]` attribute on async test functions instead of `#[test]`. You can also wrap operations in `tokio::time::timeout` to verify timeout behavior without relying on `sleep()`.

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

rstest provides parameterized tests and fixtures where you define explicit cases, while proptest generates random inputs from strategies to verify properties like roundtrip encoding or sort ordering. Use rstest for known scenarios and proptest for edge-case discovery.

How do I mock traits in Rust tests?▼

Apply the `#[automock]` attribute from mockall to your trait, which generates a mock type like `MockUserRepository`. Configure expectations with `expect_find_by_id()`, argument matchers, call counts, and return values.

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

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 percent for critical logic and 80 percent for general code.

When should I avoid using should_panic in Rust tests?▼

Avoid `#[should_panic]` when the function returns a `Result`, since asserting `is_err()` or matching specific error variants gives more precise verification. Reserve `should_panic` with an `expected` message for genuine panic conditions.