Behavior. Use when writing, consolidating, or reviewing Rust tests: contract selection, proving layer, suite economy, real dependencies, time control, and fault sensitivity.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Rust Testing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/dankosik-rust-testing)
---
name: rust-testing
description: "Behavior. Use when writing, consolidating, or reviewing Rust tests: contract selection, proving layer, suite economy, real dependencies, time control, and fault sensitivity."
---
# Rust Testing
**Behavior first.** Read the subsystem's production code before its tests to identify the observable contracts and realistic regressions worth protecting, then select the smallest layer able to watch a defect fail. Assert concrete caller- or operator-visible outcomes (status, body, Problem code and headers, committed rows, published message, telemetry event, or exit code) against independent expected values rather than tautologically re-deriving constants or mirroring internal steps, call order, or private representations. Apply a quick Mutation Mental Test to every new or edited test: mentally invert or delete the production branch it guards and confirm the test would go red.
**Smallest proving layer.** Match the harness to the boundary under test: unit tests beside pure logic, mounted `Router` tests when middleware and extractors participate, bounded loopback listeners for socket behavior, binary process tests for startup/drain/exit codes, and Compose integration suites for real providers. Assert public behavior so internal refactors stay green, while keeping platform and integration tests wherever transport, OS, SQL, or protocol semantics carry distinct behavior that in-memory checks cannot observe.
**Suite economy and consolidation.** Make every added or retained test earn its execution and maintenance cost by catching a realistic regression that types, exhaustive matches, and neighboring tests leave open. Consolidate overlapping cases around the strongest behavior check at that layer—or a compact table of distinct equivalence classes for pure logic—removing obsolete tests, duplicate setup, and unused fixtures instead of padding test counts. Treat independent safety, authorization, secret-redaction, resource-limit, timeout, and durability guards as non-fungible: never trade one away to offset growth elsewhere, and never delete the sole useful regression guard to clear a failing run.
**Real providers versus doubles.** Exercise real PostgreSQL or broker instances via `just test-integration-db` and the Compose recipes in `justfile` whenever provider semantics belong to the claim; reserve test doubles for unavailable external peers, injected faults, or deterministic inputs outside the asserted contract rather than mocking internal collaborators. Keep fixtures minimal—specifying only inputs relevant to the asserted contract—while retaining focused custom wire or body fixtures where tests inject partial reads, mid-stream errors, or cancellation timing beyond library mocks.
**Clocks, synchronization, and flake repair.** Drive paused Tokio time exclusively with Tokio timers (accounting for idle auto-advance), and synchronize concurrent steps on observable state transitions, notifications, or task joins with bounded timeouts rather than wall-clock sleeps. Repair valuable flaky tests at their timing, ordering, or shared-state root cause instead of masking them with retries or widened sleeps. In process tests, resolve built executables from Cargo's test environment or `compiler-artifact` JSON, await readiness before signalling `SIGTERM`, and wait for child termination through the existing harness.
**Fault sensitivity and discovery.** Organize tests by behavior with explicit boundary limits and independent wire fixtures where serialization compatibility matters. Reproduce bugs with a failing test first, verify non-zero executed test counts, and confirm when practical that new or consolidated guards fail for the broken behavior they claim to catch. Use `just mutants <crate> <path>`, property tests, Miri, or fuzzing selectively as discovery aids rather than mandatory completion gates.