Fuzzing and Invariant Checks
Fuzzing throws large volumes of randomized or malformed input at code to surface crashes and edge cases a human wouldn't think to test, and pairs naturally with invariant checks that assert properties which must always hold, regardless of input.
Prerequisites: Property-Based Testing
Fuzzing feeds a piece of code enormous quantities of automatically generated input, random bytes, boundary values, deliberately malformed data, and simply watches for the code to crash, hang, or misbehave. Unlike a hand-written unit test, which checks a specific input against a specific expected output, a fuzzer doesn't know what the "right" answer is; it's searching purely for inputs that break something, and it can explore far more of the input space than a human tester would ever think to write by hand.
The natural pairing is an invariant check: a property of the code's behavior that must hold true no matter what input is thrown at it, expressed as an assertion inside the code itself rather than in a separate test file. A parser might assert that its output, when re-serialized, exactly reproduces the input; a portfolio-weight calculation might assert that weights always sum to 1 regardless of the inputs fed in. Fuzzing without an invariant check can only catch crashes; fuzzing with one can catch silent wrong answers too, because the fuzzer can generate a huge number of inputs and the invariant flags the first one that produces a violation, even if the code runs to completion without any visible error.
In a quant codebase, this combination is particularly good at catching parsing bugs in market-data feeds and numerical edge cases (division by a near-zero volume, an option with zero time to expiry) that a hand-picked set of test cases is unlikely to include.
Fuzzing generates large volumes of adversarial input automatically rather than relying on a human to think of edge cases, and it is most powerful paired with an invariant check, an assertion of something that must always be true, because that lets the fuzzer catch silent wrong answers, not just crashes.
Discussion
💡 Discussion rules
- Ask and answer about this concept. Off-topic gets removed.
- No homework dumps. Show what you tried first.
- Corrections are welcome. Cite a source when you claim an error.
Loading discussion…
Related concepts
Practice in interviews
Further reading
- Zeller, The Fuzzing Book