Property tests and fuzzing concepts
Quick answer
Property tests check general rules across generated inputs; fuzzing explores inputs to find crashes or other unexpected behavior. Both complement fixed regression cases.
Define the property first
For a sorting function, sortedness and preservation of elements are separate properties. Proptest can generate cases and shrink failures; cargo-fuzz can feed varied inputs to a target. The following bounded loops are deterministic demonstrations, not full property-testing or fuzzing tools.
fn main() { for n in 0..=8 { let original: Vec<_> = (0..n).collect(); let mut v = original.clone(); v.reverse(); v.reverse(); assert_eq!(v, original); } println!("9 cases");}Expected stdout (not executed):
9 casesReversing twice should restore the input.
fn main() { for b in 0u8..=255 { let s = [b]; let _ = std::str::from_utf8(&s); } println!("256 cases");}Expected stdout (not executed):
256 casesInvalid UTF-8 should be reported as an error rather than assumed valid.
Common mistake
No observed crash is not proof of safety or complete coverage.
Try it yourself
Add a property that reversing preserves the length.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Property tests and fuzzing concepts — practice quiz
Choose one answer per question. Code examples are predictions; review explanations after attempting them.
A sorting function returns an empty list for every input. Which property exposes this despite sortedness?
Property tests and fuzzing concepts — example 1. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn main() { for n in 0..=8 { let original: Vec<_> = (0..n).collect(); let mut v = original.clone(); v.reverse(); v.reverse(); assert_eq!(v, original); } println!("9 cases"); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.
Property tests and fuzzing concepts — example 2. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn main() { for b in 0u8..=255 { let s = [b]; let _ = std::str::from_utf8(&s); } println!("256 cases"); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.