Rust Test
Rule
Test public behavior with deterministic tests. Prefer unit tests near implementation,
integration tests for crate behavior, doctests for documented examples, and regression tests
for bugs.
Hard Stops
Stop before:
- Tests touch production services, real secrets, user files, live databases, or shared
mutable infrastructure.
- Adding test dependencies such as
insta, proptest, quickcheck, testcontainers,
wiremock, mockall, or Tokio test utilities without approval or project precedent.
- Snapshot tests would hide unclear behavior instead of documenting an intentional contract.
- Async or concurrency tests rely on sleeps rather than deterministic synchronization.
Defaults
- Use
#[test], module-level unit tests, tests/*.rs integration tests, and doctests.
- Use
#[tokio::test] only for Tokio projects; keep runtime features explicit.
- Use
tempfile when filesystem isolation is needed and approved.
- Use
assert_eq!/matches! and meaningful failure messages; avoid over-broad snapshots.
- Use
insta only for stable structured output where focused assertions are worse.
- Use
proptest for parsers, serializers, normalizers, and invariant-heavy code.
- Use
wiremock or local axum/hyper test servers for HTTP clients; never call live
services by default.
- Use
cargo-nextest when already configured; otherwise cargo test is the baseline.
Workflow
- Inspect existing tests, features, fixtures, and wrapper commands.
- For bugs, write or run a focused failing regression test first when practical.
- Cover success, failure, edge cases, cancellation, and public error behavior.
- Keep fixtures small and local; use files only when file format/path behavior is contract.
- Run targeted
cargo test <name> or package-specific tests.
- Run full
cargo test --all-targets --all-features or project wrapper.
- Run doctests, async tests, property seeds, snapshots, or coverage only when relevant.
- Run
just check before handing back.
Coverage
Use cargo llvm-cov only when configured or approved. Coverage is a signal; do not add weak
assertions or test-only branches to raise a number. Prefer assertions that would fail for
real regressions.
Completion
Report tests added, commands run, async/snapshot/property/container choices, coverage result
when measured, and remaining untested risk.
Source: nyquistwilder/personal-pi — distributed by TomeVault.
1---2name: rust-test3description: Rust testing workflow for unit, integration, doc, snapshot, property, async, regression, and coverage-aware tests in greenfield Cargo projects. Use for creating, improving, validating, or reviewing Rust tests. Use when this capability is needed.4---56# Rust Test78## Rule910Test public behavior with deterministic tests. Prefer unit tests near implementation,11integration tests for crate behavior, doctests for documented examples, and regression tests12for bugs.1314## Hard Stops1516Stop before:1718- Tests touch production services, real secrets, user files, live databases, or shared19 mutable infrastructure.20- Adding test dependencies such as `insta`, `proptest`, `quickcheck`, `testcontainers`,21 `wiremock`, `mockall`, or Tokio test utilities without approval or project precedent.22- Snapshot tests would hide unclear behavior instead of documenting an intentional contract.23- Async or concurrency tests rely on sleeps rather than deterministic synchronization.2425## Defaults2627- Use `#[test]`, module-level unit tests, `tests/*.rs` integration tests, and doctests.28- Use `#[tokio::test]` only for Tokio projects; keep runtime features explicit.29- Use `tempfile` when filesystem isolation is needed and approved.30- Use `assert_eq!`/`matches!` and meaningful failure messages; avoid over-broad snapshots.31- Use `insta` only for stable structured output where focused assertions are worse.32- Use `proptest` for parsers, serializers, normalizers, and invariant-heavy code.33- Use `wiremock` or local `axum`/`hyper` test servers for HTTP clients; never call live34 services by default.35- Use `cargo-nextest` when already configured; otherwise `cargo test` is the baseline.3637## Workflow38391. Inspect existing tests, features, fixtures, and wrapper commands.402. For bugs, write or run a focused failing regression test first when practical.413. Cover success, failure, edge cases, cancellation, and public error behavior.424. Keep fixtures small and local; use files only when file format/path behavior is contract.435. Run targeted `cargo test <name>` or package-specific tests.446. Run full `cargo test --all-targets --all-features` or project wrapper.457. Run doctests, async tests, property seeds, snapshots, or coverage only when relevant.468. Run `just check` before handing back.4748## Coverage4950Use `cargo llvm-cov` only when configured or approved. Coverage is a signal; do not add weak51assertions or test-only branches to raise a number. Prefer assertions that would fail for52real regressions.5354## Completion5556Report tests added, commands run, async/snapshot/property/container choices, coverage result57when measured, and remaining untested risk.5859---60> Source: [nyquistwilder/personal-pi](https://github.com/nyquistwilder/personal-pi) — distributed by [TomeVault](https://tomevault.io).61<!-- tomevault:4.0:skill_md:2026-06-16 -->