LLM Skills
~/catalog/testing & quality//rust-test
Testing & qualityGitHub source

Tests rust

/rust-test

Create, run, and improve Rust tests to ensure that changes are secure.

affaan-maffaan-m
240.5k
May 20, 2026
MIT License
// skill content

--- description: Enforce TDD workflow for Rust. Write tests first, then implement. Verify 80%+ coverage with cargo-llvm-cov. --- # Rust TDD Command This command enforces test-driven development methodology for Rust code using #[test], rstest, proptest, and mockall. ## What This Command Does 1. Define Types/Traits: Scaffold function signatures with todo!() 2. Write Tests: Create comprehensive test module (RED) 3. Run Tests: Verify tests fail for the right reason 4. Implement Code: Write minimal code to pass (GREEN) 5. Refactor: Improve while keeping tests green 6. Check Coverage: Ensure 80%+ coverage with cargo-llvm-cov ## When to Use Use /rust-test when: - Implementing new Rust functions, methods, or traits - Adding test coverage to existing Rust code - Fixing bugs (write failing test first) - Building critical business logic - Learning TDD workflow in Rust ## TDD Cycle `` RED -> Write failing test first GREEN -> Implement minimal code to pass REFACTOR -> Improve code, tests stay green REPEAT -> Next test case ` ## Example Session ``text User: /rust-test I need a function to validate user registration Agent: # TDD Session: Registration Validator ## Step 1: Define Interface `rust // src/validator.rs pub struct RegistrationRequest { pub name: String, pub email: String, pub password: String, } pub enum ValidationResult { Valid, Invalid(Vec<String>), } pub fn validate_registration(request: &RegistrationRequest) -> ValidationResult { todo!() } ` ## Step 2: Write Tests (RED) `rust #[cfg(test)] mod tests { use super::*; #[test] fn valid_registration_returns_valid() { let request = RegistrationRequest { name: "Alice".into(), email: "alice@example.com".into(), password: "SecureP@ss1".into(), }; assert!(matches!(validate_registration(&request), ValidationResult::Valid)); } #[test] fn blank_name_returns_invalid() { let request = RegistrationRequest { name: "".into(), email: "alice@example.com".into(), password: "SecureP@ss1".into(), }; match validate_registration(&request) { ValidationResult::Invalid(errors) => { assert!(errors.contains(&"Name is required".to_string())); } ValidationResult::Valid => panic!("expected Invalid"), } } #[test] fn invalid_email_returns_invalid() { let request = RegistrationRequest { name: "Alice".into(), email: "not-an-email".into(), password: "SecureP@ss1".into(), }; assert!(matches!( validate_registration(&request), ValidationResult::Invalid(_) )); } #[test] fn short_password_returns_invalid() { let request = RegistrationRequest { name: "Alice".into(), email: "alice@example.com".into(), password: "short".into(), }; assert!(matches!( validate_registration(&request), ValidationResult::Invalid(_) )); } } ` ## Step 3: Run Tests : Verify FAIL `bash $ cargo test running 4 tests test tests::valid_registration_returns_valid ... FAILED (not yet implemented) test tests::blank_name_returns_invalid ... FAILED test tests::invalid_email_returns_invalid ... FAILED test tests::short_password_returns_invalid ... FAILED ` Tests fail as expected (todo! panic). ## Step 4: Implement Minimal Code (GREEN) `rust pub fn validate_registration(request: &RegistrationRequest) -> ValidationResult { let mut errors = Vec::new(); if request.name.trim().is_empty() { errors.push("Name is required".into()); } if !request.email.contains('@') { errors.push("Invalid email format".into()); } if request.password.len() < 8 { errors.push("Password must be at least 8 characters".into()); } if errors.is_empty() { ValidationResult::Valid } else { ValidationResult::Invalid(errors) } } ` ## Step 5: Run Tests : Verify PASS `bash $ cargo test running 4 tests test tests::valid_registration_returns_valid ... ok test tests::blank_name_returns_invalid ... ok test tests::invalid_email_returns_invalid ... ok test tests::short_password_returns_invalid ... ok test result: ok. 4 passed; 0 failed ` All tests passing! ## Step 6: Check Coverage `bash $ cargo llvm-cov Coverage: 100.0% of lines ` Coverage: 100% ## TDD Complete! `` ## Test Patterns ### Unit Tests `rust #[cfg(test)] mod tests { use super::*; #[test] fn adds_two_numbers() { assert_eq!(add(2, 3), 5); } #[test] fn handles_error() -> Result<(), Box<dyn std::error::Error>> { let result = parse_config(r#"port = 8080"#)?; assert_eq!(result.port, 8080); Ok(()) } } ` ### Parameterized Tests with rstest ``rust use

// original public source
affaan-m/ECC
/commands/rust-test.md
License: MIT License
Independent project, not affiliated with Anthropic. This skill remains the property of its original author.
// install this skill
Paste this command in your terminal at the root of your project:
mkdir -p .claude/commands && curl -o ".claude/commands/rust-test.md" "https://raw.githubusercontent.com/affaan-m/ECC/main/commands/rust-test.md"
Then in Claude Code, type /rust-test to activate it.
open_in_newOpen original source
// save
Save available after sign in.
loginSign in to save
// information
Creatoraffaan-m
Stars 240.5k
LicenseMIT License
UpdatedMay 20, 2026
Format.md
AccessFree
// similar

Skills Testing & quality

View allarrow_forward