A test automation framework supplies reusable structure for defining, executing, and reporting tests. Rust includes a built-in unit testing framework that catches regressions and checks requirements before shipping, but it leaves several conveniences to libraries or custom code. section 6.0
Extend Rust’s built-in framework according to the testing problem:
- Use parameterized or test-case for basic parameterized tests. section 6.3
- Use rstest when tests need fixtures, or assert2 for Catch2-inspired assertions. section 6.3
- Use proptest for generated inputs, automatic result checking, and minimized failing cases; retain hand-picked values for known specifications. section 6.3
- Tune randomized test counts because property testing can consume additional CPU and cannot practically cover every value in large domains. section 6.3
Listing 6.3 Code listing of adder with proptest
pub fn add<T: std::ops::Add<Output = T>>(a: T, b: T) -> T {
a + b
}
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*; #1
proptest! {
#[test]
fn test_add(a: i64, b: i64) { #2
assert_eq!(add(a, b), a + b); #3
}
}
}
The proptest listing shows a generic Rust function, generated i64 inputs, and an assertion that exposes arithmetic overflow. section 6.3
Finding and correcting overflow
A property test for generic addition can fail with a minimized pair of i64 values that overflows. Changing the implementation to use WrappingAdd and asserting against wrapping_add makes the intended behavior explicit; cargo test then passes. section 6.3



