Rust Testing Workflow
Purpose
Run the narrowest useful Rust tests, explain failures clearly, and keep test layout aligned with Cargo's model.
Cargo test behavior matters because one command can compile and run unit tests, integration tests, documentation tests, and examples. The skill should make that scope explicit instead of treating cargo test as a black box.
Source Check
Use repo-local Rust files, checked-out dependency sources, Dash MCP or Dash HTTP for installed Rust docsets, and then official Rust documentation when Dash/local coverage is missing or stale:
Translate test behavior into the concrete command and failure mode in the repository.
Test Layout
- Put unit tests near implementation when they need private module access.
- Put integration tests under
tests/ when they should use the crate like an external caller.
- Use documentation tests when examples in public API docs should compile and run.
- Use
examples/ when sample binaries should compile as part of validation.
- Use feature-gated tests only when the crate's feature matrix is part of the public behavior.
Command Selection
Start narrow, then widen:
cargo test
Target one package in a workspace:
cargo test -p package-name
Run all workspace tests:
cargo test --workspace
Run all targets and features when feature interactions matter:
cargo test --all-targets --all-features
Filter by test name:
cargo test some_test_name
Show test output:
cargo test some_test_name -- --nocapture
Run documentation tests only when public docs are the focus:
cargo test --doc
Failure Triage
Classify failures by the first concrete break:
- compile failure: source, dependency, feature, target, or MSRV problem
- unit test failure: internal behavior changed
- integration test failure: public behavior or crate boundary changed
- doctest failure: public example or documentation drifted
- feature failure: optional dependency or cfg path broke
- workspace failure: package selection, shared dependency, or target matrix issue
Read the first relevant compiler or test error before changing code. Rust output is usually precise; preserve that precision in the user-facing explanation.
Implementation Guidance
- Add tests at the same boundary the user cares about.
- Prefer deterministic tests over sleeps, timing assumptions, or network calls.
- Use temporary directories for filesystem behavior.
- Avoid snapshot tests unless the repo already uses them or the output is intentionally broad.
- Keep error-message assertions focused on stable, user-visible text.
Output Shape
Return:
Test scope: package, workspace, target, feature, or doc-test boundary.
Commands: exact commands run or recommended.
Result: pass, fail, or skipped with the concrete reason.
Failure mode: compile, unit, integration, doctest, feature, or workspace issue.
Fix direction: the smallest code, test, dependency, or docs change that addresses the failure.
Guardrails
- Do not run broad feature or workspace matrices first when a targeted command proves the change.
- Do not hide compile failures behind test summaries.
- Do not weaken tests to match broken behavior unless the user explicitly approves the behavior change.
- Do not add network-dependent tests without a repo-owned test strategy for them.
1---2name: testing-workflow3description: Plan, run, and triage Rust tests with Cargo, including unit tests, integration tests, documentation tests, examples compiled by cargo test, targeted reruns, feature matrices, workspace package selection, and failure explanation. Use when adding tests, running Rust validation, or diagnosing cargo test failures.4license: Apache-2.05---67# Rust Testing Workflow89## Purpose1011Run the narrowest useful Rust tests, explain failures clearly, and keep test layout aligned with Cargo's model.1213Cargo test behavior matters because one command can compile and run unit tests, integration tests, documentation tests, and examples. The skill should make that scope explicit instead of treating `cargo test` as a black box.1415## Source Check1617Use repo-local Rust files, checked-out dependency sources, Dash MCP or Dash HTTP for installed Rust docsets, and then official Rust documentation when Dash/local coverage is missing or stale:1819- [Cargo tests guide](https://doc.rust-lang.org/cargo/guide/tests.html)20- [`cargo test`](https://doc.rust-lang.org/cargo/commands/cargo-test.html)21- [The Rust book testing chapter](https://doc.rust-lang.org/book/ch11-00-testing.html)22- [Cargo features reference](https://doc.rust-lang.org/cargo/reference/features.html)2324Translate test behavior into the concrete command and failure mode in the repository.2526## Test Layout2728- Put unit tests near implementation when they need private module access.29- Put integration tests under `tests/` when they should use the crate like an external caller.30- Use documentation tests when examples in public API docs should compile and run.31- Use `examples/` when sample binaries should compile as part of validation.32- Use feature-gated tests only when the crate's feature matrix is part of the public behavior.3334## Command Selection3536Start narrow, then widen:3738```bash39cargo test40```4142Target one package in a workspace:4344```bash45cargo test -p package-name46```4748Run all workspace tests:4950```bash51cargo test --workspace52```5354Run all targets and features when feature interactions matter:5556```bash57cargo test --all-targets --all-features58```5960Filter by test name:6162```bash63cargo test some_test_name64```6566Show test output:6768```bash69cargo test some_test_name -- --nocapture70```7172Run documentation tests only when public docs are the focus:7374```bash75cargo test --doc76```7778## Failure Triage7980Classify failures by the first concrete break:8182- compile failure: source, dependency, feature, target, or MSRV problem83- unit test failure: internal behavior changed84- integration test failure: public behavior or crate boundary changed85- doctest failure: public example or documentation drifted86- feature failure: optional dependency or cfg path broke87- workspace failure: package selection, shared dependency, or target matrix issue8889Read the first relevant compiler or test error before changing code. Rust output is usually precise; preserve that precision in the user-facing explanation.9091## Implementation Guidance9293- Add tests at the same boundary the user cares about.94- Prefer deterministic tests over sleeps, timing assumptions, or network calls.95- Use temporary directories for filesystem behavior.96- Avoid snapshot tests unless the repo already uses them or the output is intentionally broad.97- Keep error-message assertions focused on stable, user-visible text.9899## Output Shape100101Return:1021031. `Test scope`: package, workspace, target, feature, or doc-test boundary.1042. `Commands`: exact commands run or recommended.1053. `Result`: pass, fail, or skipped with the concrete reason.1064. `Failure mode`: compile, unit, integration, doctest, feature, or workspace issue.1075. `Fix direction`: the smallest code, test, dependency, or docs change that addresses the failure.108109## Guardrails110111- Do not run broad feature or workspace matrices first when a targeted command proves the change.112- Do not hide compile failures behind test summaries.113- Do not weaken tests to match broken behavior unless the user explicitly approves the behavior change.114- Do not add network-dependent tests without a repo-owned test strategy for them.