What does this skill do?

The Testing in Rust with TDD Skill provides comprehensive patterns and workflows for writing reliable tests in Rust using the TDD (Red-Green-Refactor) methodology. It covers everything from unit and parameterized tests with rstest to property-based testing with proptest, mocking with mockall, asynchronous tests with Tokio, and code coverage measurement with llvm-cov.

TDD Cycle: Test-Drive-Design-Green-Refactor
Write the test first using `everything!()`, verify the failure, implement the minimum required, and refactor while keeping the test passing.
Parameterized and property-based tests
Use `rstest` for multiple test cases and `proptest` to generate random inputs that validate invariants.
Dependency mocking
Isolate external dependencies using mockall and validate interactions using call expectations.
Coverage in CI
Measure coverage using the llvm-cov command and apply --fail-under-lines 80 to ensure a minimum threshold in pipelines.

Usage examples

🔴 Basic TDD Cycle
Write a test for a function `add(a, b)` that adds two integers using the Red-Green-Refactor TDD cycle.
🧩 Parameterized test
Create a parameterized test using rstest that checks the length of several text strings.
🤖 Mock with mockall
Generate a mock of the UserRepository trait using mockall and verify that `find_by_id` returns the correct user.
📊 Minimum coverage
Configure the llvm-cov job so that the CI pipeline fails if coverage drops below 80%.

Features

Complete TDD Methodology Red-Green-Refactor workflow with failure verification before deployment and safe refactoring.
Parameterized tests with rstest Define multiple cases using #[case] and execute each one independently.
Property-based testing with Proptest Automatically generates random inputs to validate invariants across a wide range of data.
Mocking with mockall Create automatic mocks of traits using #[automock] and define call expectations and return values.
Asynchronous Tests and Coverage Test async code with #[tokio::test] and measure code coverage using the llvm-cov plugin and HTML reports.

Frequently asked questions

The main crates are rstest, proptest, mockall, and tokio. You can add them to your project using `cargo add rstest proptest mockall tokio --dev`.
Yes. The skill includes templates for asynchronous tests using #[tokio::test] and `await` in the assertions.
Install cargo-llvm-cov with `cargo install cargo-llvm-cov` and run `cargo llvm-cov --html` for a visual report or `--fail-under-lines 80` to set a minimum threshold.
Yes. The skill is designed to be integrated into CI: it combines `cargo test`, `cargo fmt --check`, `cargo clippy`, and `cargo llvm-cov --fail-under-lines 80` to validate formatting, linting, and code coverage.
Testing in Rust with TDD — Patterns and Workflows with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.