rust-tests-guidelines

Codify Rust test best practices for unit, integration, and property-based testing.

6.2k|590|Updated May 5, 2016
One-click install
npx skills add https://github.com/RediSearch/RediSearch --skill rust-tests-guidelines
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-tests-guidelines
Source: https://github.com/RediSearch/RediSearch/tree/main/.skills/rust-tests-guidelines
Command: npx skills add https://github.com/RediSearch/RediSearch --skill rust-tests-guidelines

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides clear, scalable guidelines for writing reliable tests in Rust projects, helping teams ensure code quality and maintainability.

Core Features & Use Cases

  • Unit tests: Validate individual components through small, deterministic tests.
  • Integration tests: Verify interactions between modules and crates.
  • Property-based testing: Use tools like proptest to explore invariants and edge cases.
  • Snapshot testing: Adopt insta-style snapshots for stable, regression-free outputs.

Quick Start

Create tests under tests/ or within #[cfg(test)] modules, then run cargo test to execute them.

Frequently Asked Questions about rust-tests-guidelines

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

FAQPage Schema
How do I organize and run tests in a Rust project?

Organize Rust tests in #[cfg(test)] modules within source files or in a tests/ directory at your crate root. Run all tests with cargo test, which discovers and executes unit, integration, and property-based tests automatically.

What's the difference between unit tests and integration tests in Rust?

Unit tests validate individual components and live in #[cfg(test)] modules alongside source code. Integration tests verify interactions between modules and crates; place them in the tests/ directory where cargo test runs them as separate binaries.

How do I use property-based testing in Rust?

Property-based testing explores edge cases and invariants by generating random inputs. Use proptest to define properties your code must hold across many test cases, catching bugs unit tests might miss through exhaustive input variation.

What is snapshot testing and when should I use insta?

Snapshot testing captures outputs and compares future runs against stored snapshots to detect regressions. Insta provides a Rust snapshot testing library that stores snapshots inline or as separate files, ideal for validating complex outputs remain stable.

Can I combine unit tests, integration tests, and property-based tests in one Rust project?

Yes. Rust projects scale across all three testing types: use unit tests for isolated logic, integration tests for cross-module behavior, and property-based tests with proptest to verify invariants. Run all with cargo test.

What's the best way to structure tests across multiple Rust crates?

Place unit tests in #[cfg(test)] modules within each crate's library code. Use the tests/ directory in each crate for integration tests. This structure keeps tests close to implementation while enabling end-to-end validation across crate boundaries.