/rust:testingfrom rust
Use when writing, editing, fixing, strengthening, pruning, or grading Rust tests, covering flaky tests, fixtures, rstest, proptest, insta, nextest, doubles, real services, and cargo-mutants
Ships in rust. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Covers Rust tests that cargo nextest runs, cargo insta checks, and cargo mutants grades. Use code:test for test design. Use rust:coding for the code rules test code keeps.
Tests use each crate below before a hand-written equivalent:
| [INDEX] | [FIELD] | [CRATES] |
|---|---|---|
| [01] | Runner | cargo-nextest |
| [02] | Table-driven tests | rstest |
| [03] | Generated inputs | proptest, proptest-state-machine, proptest-derive |
| [04] | Snapshots | insta, cargo-insta, insta-cmd |
| [05] | Mutation | cargo-mutants |
| [06] | HTTP peers | wiremock |
| [07] | Services in containers | testcontainers, testcontainers-modules |
| [08] | Controlled time | tokio with test-util |
| [09] | Scripted byte peers | tokio-test |
| [10] | Folders | tempfile |
| [11] | Captured events | tracing-test |
| [12] | Diffs and tolerances | similar-asserts, approx |
| [13] | Benchmarks | criterion |
| [14] | Custom harnesses | libtest-mimic |
[REFERENCES]:
Placeholders mean one thing each across these files: <crate> the crate under test, <package> the package holding its tests, <target> that package's test target, <module> a module of cases over one subject, <function> a test function, <row> an rstest row's name, <test> one test's whole name, <source> a production file, <seconds> a per-mutant timeout.
Each test is seen red for its named reason before code makes it green, once code:test steps 1 to 6 fixed its source, partitions, and oracle:
Ok(0), Vec::new()), as a compile error or an early panic is no redcargo nextest run -p <package> -E 'test(/^<module>::<function>(::|$)/)', and read the assertion's left and rightgit add --intent-to-add on each new file and git diff --default-prefix <base> > <diff> (<base> the commit the change started from), then the mutation command with --in-diff <diff>no tests to run (exit status 4) reads as a filter matching no name, a test file no mod line declares, or a package the profile's default-filter drops.
Tests written for code that already exists take their red from a break:
cargo mutants --re '<mutant>' with the test's filter applies one break per mutant, <mutant> a line cargo mutants --list prints<source>, restored from a copy after its red runMutation runs follow a green cargo nextest run over every package test_package names, .cargo/mutants.toml holding the choices from the mutation reference:
cargo mutants --baseline=skip --timeout <seconds> --file <source> -- -E 'test(/^<module>::<function>(::|$)/)'
<seconds> takes cargo-mutants' own rule (five times the suite's run, at least 20), and a run without -- -E .. tests the whole suite.
Red tests change code or test once the behavior's source decides which is wrong:
cargo nextest run -p <package> -E 'test(=<test>)' --no-capture, and read the panic's location or the printed errorFlaky tests take a stress run as their red:
cargo nextest run -p <package> -E 'test(=<test>)' --stress-count <count>, where one red run shows nondeterminism inside the test-E 'binary_id(<package>::<target>)', where red only here shows an outside resource siblings shareBodies return Result<(), E>, E the one error their ? steps meet, and a test-local Failure where they meet more than one:
#[derive(Debug, thiserror::Error)]
enum Failure {
#[error(transparent)]
Io(#[from] io::Error),
#[error(transparent)]
Size(#[from] SizeError),
#[error("{file}: {source}")]
Count { file: PathBuf, source: ParseIntError },
}
Error: <Debug> with no line, and each variant holds the subject it refused, so a foreign error naming no input (ParseIntError) takes a variant holding itthiserror::Error reads each field, where a Debug derive alone leaves them unread under dead_codeOption values a later step needs bind through .ok_or(<variant>)?, and an expected error a step reads through let Err(error) = &got else { .. }claims stays out as a second form of ? and assert_matches!, and a variant's subject names the input where its panic named a lineassert_matches! is stable at std::assert_matches and takes use std::assert_matches;Each fact takes the assertion that prints it whole, its message interpolating the case's inputs:
| [INDEX] | [FACT] | [FORM] |
|---|---|---|
| [01] | Value | assert_eq!(got, want, "<inputs>") over the whole record or Result |
| [02] | Facts of one act | assert_eq!((status, stdout), (Some(0), want), "<inputs>") |
| [03] | Variant in part | assert_matches!(got, Err(Error::Http(error)) if error.status() == ..) |
| [04] | Unordered result | BTreeSet equality, Itertools::counts for a multiset |
| [05] | Large value | similar_asserts::assert_eq!, printing a line diff |
| [06] | Float | assert_abs_diff_eq! for a stated epsilon or a value near zero, assert_relative_eq! otherwise |
| [07] | Generated case | prop_assert_eq!(got, want, "<inputs>") |
Domain assertions take #[track_caller], and a failure points at the calling test's line:
#[track_caller]
fn assert_refusals(texts: &[&str], want: &[SizeError]) {
assert_eq!(refused(texts.iter().copied()).into_iter().counts(), want.iter().cloned().counts(), "refusals of {texts:?}");
}
refused returns the refusal of each text that fails to parse, and Itertools::counts compares refusals as a multiset.
Each form on the left hides what broke:
| [INDEX] | [FORBIDDEN] | [CORRECT] |
|---|---|---|
| [01] | assert!(matches!(..)), assert!(a == b) | assert_matches!, assert_eq!, printing the value |
| [02] | .contains("<word>") on rendered error text | Variant and fields of the typed error |
| [03] | to_string() of a value compared with text | Comparison of the value, or the whole derived Display users read |
| [04] | Independent cases sharing one for loop and check | #[case::<row>] rows |
| [05] | len() == len() && all(contains) | Set or counts equality, as the hand form passes [A, A] against [A, B] |
| [06] | if let Ok(..) or if let Some(..) around a check | ?, or assert_matches! on the absent case |
Test smells name a test that decides nothing or reports a wrong verdict. Each kind keeps its code:test meaning, the Rust sign below finds it, and its action decides what Editing does with it:
| [INDEX] | [KIND] | [RUST_SIGN] | [ACTION] |
|---|---|---|---|
| [01] | Tautological | Expected value whose one source is production text (steps(&plan), a pasted script) | Delete |
| [02] | Vacuous | Dropped result of a poll or timeout, a spawned handle never joined, a file no mod line declares | Delete |
| [03] | Weak | is_some(), !is_empty(), len() == n, or a substring as the one check of the claim a name states | Delete |
| [04] | Echo | assert_eq!(stub_answer, got) with no call of crate code between | Delete |
| [05] | Blind negative | Err(_), is_err(), #[should_panic] with no expected, a wildcard over fields telling paths apart | Delete |
| [06] | Unreached | Arrangement a break at its claimed branch leaves green, the input landing in another partition | Delete |
| [07] | Unlabelled pin | Literal in assert_eq! recorded from a run outside snapshot review, over code with a source | Delete |
| [08] | Change detector | Assertion on a constant's value, an unqualified Debug text, or a variant's name as text | Delete |
| [09] | Dependency | Vendor or crate fact no decision of the crate depends on | Delete |
| [10] | Type-proven | Fact the compiler proves: a return type, a trait bound, a variant's existence | Delete |
| [11] | Ignored | #[ignore] no profile or task runs with --run-ignored | Delete |
| [12] | Coupled | Order no contract states, an item made pub or #[doc(hidden)] for a test package | Rebuild |
| [13] | Costly | Real-clock wait where an in-memory peer fits, rounds repeating a partition a sibling holds | Rebuild |
| [14] | Flaky | sleep deciding order, wall-clock bounds across processes, a port probed free, HashMap order | Fix at cause |
Kept tests catch a mutant no other test catches, or hold a partition their source states. Rewriting a smelly test in place keeps its author's case list and reading of the code, the cause of its defect, and a behavior worth keeping gets a new test written red first. Pins over code with no source stay as characterization, named for it, until that behavior is decided.
Rows from the source's partitions and limits come first, and each missed mutant then names the case kind that catches it through the mutation reference's genre table:
| [INDEX] | [CASE_KIND] | [FORM] |
|---|---|---|
| [01] | Partitions | One #[case::<row>] per partition its source states |
| [02] | Limits | Rows on each side of every limit: 16_384 and 16_385, a nanosecond around a deadline |
| [03] | Refusals | Every rule broken at once beside each rule kept nearest its limit |
| [04] | Reference | Second implementation as oracle: git, cargo metadata, /bin/sh, a textbook pass |
| [05] | Property | #[property_test] beside the rows, draws shaped onto each limit |
| [06] | Relation | Output equal or unequal to a related input's, in place of a pinned value |
| [07] | Model | prop_state_machine! against a standard-library value |
| [08] | Real engine | Suite against the engine whose answer is the behavior |
Editing, improving, or grading a suite runs in order, and a grade stops after step 4:
cargo nextest run -p <package>, then the flaky stress run over its binary, where any red sends the suite through Failures first--file <source> for each production file of <crate>, its caught.txt, missed.txt, and per-test tally kept#[case] rows, rows following one rule gaining a #[property_test] beside them, proptest! blocks to #[property_test], shared checks to #[track_caller] assertionsreferences/boundaries.md (opens in a new tab)references/fixtures.md (opens in a new tab)references/generated.md (opens in a new tab)references/mutation.md (opens in a new tab)references/snapshots.md (opens in a new tab)references/suites.md (opens in a new tab)references/tables.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub bsamiee/rasm --plugin rust3 skills in this plugin
/codingUse when writing or reviewing Rust, covering functional design with algebraic types, results, traits, and async effects/debuggingUse when debugging a Rust program, test, or proc macro at runtime, covering debug info profiles, CodeLLDB sessions, panic and abort stops, values and expressions, breakpoints on Rust names, async tasks, undefined behavior checks, and optimized buildsOther plugins' skills for the same job