.opencode/commands/rust-test.md
Implement using Rust TDD methodology: $ARGUMENTS
Apply test-driven development with Rust idioms:
#[cfg(test)] modulespub struct Input {
// fields
}
pub fn process(input: &Input) -> Result<Output, Error> {
todo!()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn valid_input_succeeds() {
let input = Input { /* ... */ };
let result = process(&input);
assert!(result.is_ok());
}
#[test]
fn invalid_input_returns_error() {
let input = Input { /* ... */ };
let result = process(&input);
assert!(result.is_err());
}
}
cargo test
pub fn process(input: &Input) -> Result<Output, Error> {
// Minimal implementation that handles both paths
validate(input)?;
Ok(Output { /* ... */ })
}
cargo llvm-cov
cargo llvm-cov --fail-under-lines 80
cargo test # Run all tests
cargo test -- --nocapture # Show println output
cargo test test_name # Run specific test
cargo test --no-fail-fast # Don't stop on first failure
cargo test --lib # Unit tests only
cargo test --test integration # Integration tests only
cargo test --doc # Doc tests only
cargo bench # Run benchmarks
src/
├── lib.rs # Library root
├── service.rs # Implementation
└── service/
└── tests.rs # Or inline #[cfg(test)] mod tests {}
tests/
└── integration.rs # Integration tests
benches/
└── benchmark.rs # Criterion benchmarks
TIP: Use rstest for parameterized tests and proptest for property-based testing.