How to use proptest for property testing

Use proptest to define property-based tests that automatically generate random inputs to verify your code's logic holds true across all scenarios.

Use proptest by adding it as a dev-dependency, defining a test function with the #[test] attribute, and running a strategy via prop_assert! or prop_assert_eq! to verify properties across random inputs.

#[cfg(test)]
mod tests {
    use proptest::prelude::*;

    #[test]
    fn test_addition_commutative() {
        proptest!(|(a in any::<i32>(), b in any::<i32>())| {
            prop_assert_eq!(a + b, b + a);
        });
    }
}

Run the tests with cargo test.