← ClaudeAtlas

rust-testinglisted

Rust testing patterns including unit tests, integration tests, async testing, property-based testing, mocking, and coverage. Follows TDD methodology.
caovinhphuc/React-OAS-Integration-v4.0 · ★ 2 · Testing & QA · score 71
Install: claude install-skill caovinhphuc/React-OAS-Integration-v4.0
# Rust Testing Patterns Comprehensive Rust testing patterns for writing reliable, maintainable tests following TDD methodology. ## When to Use - Writing new Rust functions, methods, or traits - Adding test coverage to existing code - Creating benchmarks for performance-critical code - Implementing property-based tests for input validation - Following TDD workflow in Rust projects ## How It Works 1. **Identify target code** — Find the function, trait, or module to test 2. **Write a test** — Use `#[test]` in a `#[cfg(test)]` module, rstest for parameterized tests, or proptest for property-based tests 3. **Mock dependencies** — Use mockall to isolate the unit under test 4. **Run tests (RED)** — Verify the test fails with the expected error 5. **Implement (GREEN)** — Write minimal code to pass 6. **Refactor** — Improve while keeping tests green 7. **Check coverage** — Use cargo-llvm-cov, target 80%+ ## TDD Workflow for Rust ### The RED-GREEN-REFACTOR Cycle ``` RED → Write a failing test first GREEN → Write minimal code to pass the test REFACTOR → Improve code while keeping tests green REPEAT → Continue with next requirement ``` ### Step-by-Step TDD in Rust ```rust // RED: Write test first, use todo!() as placeholder pub fn add(a: i32, b: i32) -> i32 { todo!() } #[cfg(test)] mod tests { use super::*; #[test] fn test_add() { assert_eq!(add(2, 3), 5); } } // cargo test → panics at 'not yet implemented' ``` ```rust // GREEN: Replace todo!() with minimal