Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Enforces Red-Green-Refactor TDD for Rust code, with cfg(test) unit tests, anyhow/thiserror error paths, and Arrange-Act-Assert structure.
Use this skill ↓72% 92%+20 ptsof test cases passed
Passed 23 of 25 test cases with the skill, and 18 of 25 without it.
3 of 3 safety checks passed
Not used yet
Cycle: RED (test fails) -> GREEN (minimum to pass) -> REFACTOR (cleanup, cargo test)
1. Write test in #[cfg(test)] mod tests of the SAME file
2. cargo test MODULE::tests::test_name -- must FAIL (red)
3. Implement the minimum in the function
4. cargo test MODULE::tests::test_name -- must PASS (green)
5. Refactor if needed, re-run cargo test (still green)
6. cargo fmt && cargo clippy --all-targets && cargo test (final gate)
Never skip step 2. If the test passes immediately, it tests nothing.
| Pattern | Usage | When |
|---|---|---|
| Arrange-Act-Assert | Base structure for every test | Always |
assert_eq! / assert! | Direct comparison / booleans | Deterministic values |
assert!(result.is_err()) | Error path testing | Invalid inputs |
Result<()> return type | Tests with ? operator | Fallible functions |
#[should_panic] | Expected panic | Invariants, preconditions |
tempfile::NamedTempFile | File/I/O tests | Filesystem-dependent code |
| Code Type | Test Pattern | Example |
|---|---|---|
| Pure function (str -> str) | Input literal -> assert output | assert_eq!(truncate("hello", 3), "...") |
| Parsing/filtering | Raw string -> filter -> contains/not-contains | assert!(filter(raw).contains("expected")) |
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.