Learn Rust testing patterns and TDD to improve code quality and reliability.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "rust-testing" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/rust-testing/SKILL.md 2. Save it as ~/.claude/skills/rust-testing/SKILL.md 3. Reload skills and tell me it's ready
Please design and write unit tests for this Rust module, covering happy paths, edge cases, and error handling, and explain the purpose of each test.
A well-structured set of Rust unit tests with explanations of coverage and test intent.
Please write tests for the following async Rust functions using async testing patterns, including success, timeout, and failure scenarios, and explain the required test runtime setup.
Runnable async test examples with scenario coverage and recommended runtime setup.
Using a TDD approach, first list test cases for this Rust code, then provide refactoring suggestions and add mocking, integration test, and coverage improvement plans.
A TDD-structured test plan, refactoring guidance, and an implementation plan to improve coverage.
Comprehensive Rust testing patterns for writing reliable, maintainable tests following TDD methodology.
#[test] in a #[cfg(test)] module, rstest for parameterized tests, or proptest for property-based testsRED → 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
// 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'
// GREEN: Replace todo!() with minimal implementation
pub fn add(a: i32, b: i32) -> i32 { a + b }
// cargo test → PASS, then REFACTOR while keeping tests green
// src/user.rs
pub struct User {
pub name: String,
pub email: String,
}
impl User {
pub fn new(name: impl Into<String>, email: impl Into<String>) -> Result<Self, String> {
let email = email.into();
if !email.contains('@') {
return Err(format!("invalid email: {email}"));
}
Ok(Self { name: name.into(), email })
}
pub fn display_name(&self) -> &str {
&self.name
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn creates_user_with_valid_email() {
let user = User::new("Alice", "[email protected]").unwrap();
assert_eq!(user.display_name(), "Alice");
assert_eq!(user.email, "[email protected]");
}
#[test]
fn rejects_invalid_email() {
let result = User::new("Bob", "not-an-email");
assert!(result.is_err());
assert!(result.unwrap_err().contains("invalid email"));
}
}
assert_eq!(2 + 2, 4); // Equality
assert_ne!(2 + 2, 5); // Inequality
assert!(vec![1, 2, 3].contains(&2)); // Boolean
assert_eq!(value, 42, "expected 42 but got {value}"); // Custom message
assert!((0.1_f64 + 0.2 - 0.3).abs() < f64::EPSILON); // Float comparison
Result Returns#[test]
fn parse_returns_error_for_invalid_input() {
let result = parse_config("}{invalid");
assert!(result.is_err());
// Assert specific error variant
let err = result.unwrap_err();
assert!(matches!(err, ConfigError::ParseError(_)));
}
#[test]
fn parse_succeeds_for_valid_input() -> Result<(), Box<dyn std::error::Error>> {
let config = parse_config(r#"{"port": 8080}"#)?;
assert_eq!(config.port, 8080);
Ok(()) // Test fails if any ? returns Err
}
#[test]
#[should_panic]
fn panics_on_empty_input() {
process(&[]);
}
#[test]
#[should_panic(expected = "index out of bounds")]
fn panics_with_specific_message() {
let v: Vec<i32> = vec![];
let _ = v[0];
}
my_crate/
├── src/
│ └── lib.rs
├── tests/ # Integration tests
…
Set up and manage Pi-hole DNS, blocking, and home network resolution.
Turn a design or spec into a running MVP starting point.
Write, review, and refactor C++ with modern, safe, idiomatic standards.
Design and improve Spring Boot backend architecture, APIs, and service implementation.
Review security risks for auth, inputs, secrets, APIs, and sensitive features.
Create iOS liquid glass interfaces with dynamic visuals and interactive morphing.
Build high-quality Kotlin tests with Kotest, MockK, coroutines, and coverage.
Learn idiomatic Rust patterns, ownership, concurrency, and robust error handling practices.
Write idiomatic Go tests, benchmarks, fuzz tests, and improve coverage.
Write, run, and improve Perl automated tests with coverage analysis.
Build robust Python test suites with pytest, TDD, mocking, and coverage.
Design and implement robust F# unit, property, and integration tests