rust-testing

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

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

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 patterns for writing reliable Rust tests using the standard test harness plus ecosystem crates like rstest, proptest, and mockall. ## Core Features & Use Cases - TDD Workflow Guidance: Step-by-step RED-GREEN-REFACTOR cycle with concrete Rust examples using todo!() placeholders and #[cfg(test)] modules. - Full Testing Stack Coverage: Patterns for unit tests, integration tests in tests/, async tests with #[tokio::test], doc tests, parameterized tests with rstest, property-based tests with proptest, and mocking with mockall. - Coverage and CI Integration: Commands for cargo-llvm-cov with threshold enforcement and a ready-to-use GitHub Actions workflow including fmt, clippy, tests, and coverage gates. - Use Case: When adding a new feature to a Rust crate, use this Skill to write a failing test first, mock repository traits with mockall, validate inputs with proptest strategies, and enforce 80% line coverage in CI. ## Quick Start Ask the assistant to write tests for a Rust function or module following TDD, for example: write unit tests with rstest cases and mockall mocks for my UserService.

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 tests in a `#[cfg(test)]` module inside the same file as your code, annotate each test function with `#[test]`, and use assertion macros like `assert_eq!` and `assert!`. Run them with `cargo test`.

How to mock traits in Rust tests with mockall?

Apply the `#[automock]` attribute to your trait, then create a mock instance and set expectations with methods like `expect_find_by_id().with(eq(42)).times(1).returning(...)`. Inject the mock into the service under test to isolate it from real dependencies.

What is the difference between rstest and proptest in Rust?

rstest provides parameterized tests where you explicitly list input cases with `#[case]` attributes, plus fixture injection. proptest generates random inputs from strategies to verify properties hold across many cases, such as roundtrip or ordering invariants.

How do I test async Rust code with tokio?

Replace `#[test]` with `#[tokio::test]` and mark the function `async`. You can then await futures directly and use utilities like `tokio::time::timeout` to verify timeout behavior without blocking the test runner.

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. It integrates into CI via the taiki-e/install-action GitHub Action.

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

Avoid `#[should_panic]` when the function returns a `Result`, since asserting `result.is_err()` or matching specific error variants gives more precise failure information. Reserve `#[should_panic(expected = "...")]` for genuine panic conditions only.