rust-tdd

Guides test-first Rust development with red-green-refactor cycles, fakes, and async test patterns.

2|1|Updated Aug 19, 2026
One-click install
npx skills add https://github.com/po4yka/rust-skills --skill rust-tdd-po4yka
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rust-tdd
Source: https://github.com/po4yka/rust-skills/tree/main/skills/rust-tdd
Command: npx skills add https://github.com/po4yka/rust-skills --skill rust-tdd-po4yka

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing tests after the implementation only proves the code does what the code does. This Skill enforces a disciplined red-green-refactor workflow for Rust so every test fails first for a predicted reason, and it provides concrete patterns for fakes, fault injection, async tests, and golden contracts that teams usually improvise badly. ## Core Features & Use Cases - Red-Green-Refactor Discipline: Step-by-step cycle with a triage table for reading RED results, plus verification gates using cargo fmt, clippy, nextest, and doctests. - Hand-Written Fakes with Fault Injection: Conventions for Fake* test doubles and a typed FaultQueue with OneShot/Persistent scopes to test error paths, retries, and cancellation without cfg(test) branches in production code. - Async and Golden Test Patterns: Rules for #[tokio::test] with paused time, gated fakes for in-flight assertions, JoinHandle awaiting, and blessing discipline for golden contract fixtures. - Use Case: When fixing a reported bug, write a failing reproduction test through the public API first, fix the root cause at the shared choke point, and keep the test as a permanent regression guard in the same commit. ## Quick Start Ask the agent to write a failing Rust test for the behavior you want, confirm it fails for the predicted reason, then implement the minimum code to make it pass.

Frequently Asked Questions about rust-tdd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I practice TDD in Rust with cargo test?▼

Write one failing test that asserts the predicted failure, run it with cargo nextest run --locked -p <crate> to confirm the RED, then write the minimum implementation to pass. Run cargo fmt, clippy with -D warnings, and the test suite once before each commit.

How to test error paths in Rust without modifying production code?▼

Use a hand-written fake implementing the seam trait with a typed FaultQueue of FaultSpec entries. Enqueue OneShot or Persistent faults targeting specific operations, then assert both the error mapping and that the injected fault actually fired.

Does tokio support pausing time in async tests?▼

Yes, #[tokio::test(start_paused = true)] pauses the clock so timers advance instantly when no task is ready. It requires the tokio test-util feature in dev-dependencies and the current-thread runtime flavor.

Why does my filtered cargo test run pass but run zero tests?▼

A filter matching nothing is a false green: cargo test prints 0 passed with N filtered out and exits 0. cargo-nextest instead prints an error and exits 4, so always read the test count on filtered runs.

When should I not use this TDD skill for Rust testing?▼

This skill does not cover loom concurrency testing, proptest property testing, fuzzing, mutation testing, or golden-file harness mechanics. Use the rust-test-tools skill for those techniques instead.