New to Claude Skills? Learn how to install them →

Rrtk-ai on GitHub

Rust TDD Workflow

Free

Streamline your TDD process for Rust development.

by rtk-ai75.5k stars on rtk-ai/rtk
4 views
Updated Aug 7, 2026
Get this skill

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 source

1. Install with the skills CLI

npx skills add rtk-ai/rtk/rtk-tdd --agent claude-code

2. 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-ai

Rust TDD Workflow

Three Laws of TDD

  1. Do NOT write production code without a failing test
  2. Write only enough test to fail (including compilation failure)
  3. 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

PatternUsageWhen
Arrange-Act-AssertBase structure for every testAlways
assert_eq! / assert!Direct comparison / booleansDeterministic values
assert!(result.is_err())Error path testingInvalid inputs
Result<()> return typeTests with ? operatorFallible functions
#[should_panic]Expected panicInvariants, preconditions
tempfile::NamedTempFileFile/I/O testsFilesystem-dependent code

Patterns by Code Type

Code TypeTest PatternExample
Pure function (str -> str)Input literal -> assert outputassert_eq!(truncate("hello", 3), "...")
Parsing/filteringRaw string -> filter -> contains/not-containsassert!(filter(raw).contains("expected"))
Validation/securityBoundary inputs -> assert boolassert!(!is_valid("../etc/passwd"))
Error handlingBad input -> is_err()assert!(parse("garbage").is_err())
Struct/enum roundtripConstruct -> serialize -> deserialize -> eqassert_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 to Result first, 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