
Rust TDD Workflow
FreeStreamline your TDD process for Rust development.
Free · Opens the source repo
What Rust TDD Workflow does
The Rust TDD Workflow skill is designed to enforce Test-Driven Development (TDD) principles specifically for Rust programming. By following the Red-Green-Refactor cycle, developers can ensure that they write production code only after establishing a failing test, thus promoting a disciplined approach to coding. The skill automatically triggers during implementation, testing, refactoring, and bug-fixing tasks, helping to maintain a consistent workflow that adheres to TDD practices.
This skill provides a structured approach to writing tests in Rust, utilizing idiomatic patterns such as Arrange-Act-Assert. It emphasizes the importance of writing tests that fail before writing the corresponding production code, ensuring that developers do not skip critical steps in the TDD process. The skill also includes a variety of testing patterns tailored for different scenarios, such as error handling, validation, and file I/O tests, making it easier for developers to apply best practices in their test cases.
For developers who are new to TDD or looking to reinforce their testing strategies, this skill serves as a valuable resource. It not only outlines the necessary steps to follow but also provides naming conventions and examples to guide users in structuring their tests effectively. By incorporating this skill into their workflow, developers can enhance their code quality and reliability, ultimately leading to more maintainable and robust applications.
While the Rust TDD Workflow skill is a powerful tool for enforcing TDD, it is important to note that it may not be suitable for all testing scenarios, such as those involving direct I/O operations or command executions. In such cases, developers should consider alternative testing strategies or mock implementations to achieve their testing goals.
When to use it
Use this skill when developing Rust applications and applying TDD methodologies to ensure code quality and reliability.
When not to use it
Avoid using this skill for testing scenarios that involve direct I/O or command execution, as it may not provide the necessary coverage for those cases.
What you can build with it
Implementing a New Feature
When adding a new feature to your Rust application, use this skill to ensure that you write tests first, following the TDD methodology.
Refactoring Existing Code
Utilize this skill to guide your refactoring process, ensuring that tests are in place to verify that your changes do not introduce new bugs.
Learning TDD Principles
If you're new to TDD, this skill provides structured guidance and idiomatic patterns to help you understand and apply TDD effectively in Rust.
How to install Rust TDD Workflow
View source1. Install with the skills CLI
npx skills add rtk-ai/rtk/rtk-tdd --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by rtk-aiRust TDD Workflow
Three Laws of TDD
- Do NOT write production code without a failing test
- Write only enough test to fail (including compilation failure)
- Write only enough production code to pass the failing test
Cycle: RED (test fails) -> GREEN (minimum to pass) -> REFACTOR (cleanup, cargo test)
Red-Green-Refactor Steps
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.
Idiomatic Rust Test Patterns
| 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 |
Patterns by Code Type
| 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")) |
| Validation/security | Boundary inputs -> assert bool | assert!(!is_valid("../etc/passwd")) |
| Error handling | Bad input -> is_err() | assert!(parse("garbage").is_err()) |
| Struct/enum roundtrip | Construct -> serialize -> deserialize -> eq | assert_eq!(from_str(to_str(x)), x) |
Naming Convention
test_{function}_{scenario}
test_{function}_{input_type}
Examples: test_truncate_edge_case, test_parse_invalid_input, test_filter_empty_string
When NOT to Use Pure TDD
- Functions calling
Command::new()-> test the parser, not the execution std::process::exit()-> refactor toResultfirst, then test the Result- Direct I/O (SQLite, network) -> use tempfile/mock or test the pure logic separately
- Main/CLI wiring -> covered by integration/smoke tests
Pre-Commit Gate
cargo fmt --all --check
cargo clippy --all-targets
cargo test
All 3 must pass. No exceptions. No #[allow(...)] without documented justification.
Frequently asked questions about Rust TDD Workflow
Similar skills
Spring Boot Testing
Master testing techniques for Spring Boot 4 applications.
GitHub Issues
Manage GitHub issues efficiently with MCP tools.
Geofeed Tuner
Optimize your IP geolocation feeds in CSV format.
Batch Files
Master Windows batch scripting for automation and task management.
Adobe Illustrator Scripting
Automate your Illustrator workflows with ExtendScript.
Plugin Structure
Create and organize Claude Code plugins effectively.
