Property-Based Testing¶
Instead of specifying individual examples, specify invariants that must hold for all inputs; the testing system generates diverse inputs and searches for counterexamples - trading specification precision for exploration coverage.
Tension Addressed¶
Specification Precision vs. Exploration Coverage
Recognizable As¶
Tests with random generators; invariant assertions like "for all x: reverse(reverse(x)) == x"; shrinking failed cases to minimal examples; generators for domain types
Canonical Sources¶
Claessen & Hughes, "QuickCheck" (2000); Hughes, "QuickCheck Testing for Fun and Profit" (2007)
Transfers To¶
Fuzzing in security testing; Monte Carlo methods; statistical sampling; formal verification approaches
Sub-concepts: - Generators: Produce random instances of types - Shrinking: Reduce failing cases to minimal counterexamples - Invariants: Properties that must hold regardless of input
Property-based testing excels at finding edge cases humans wouldn't think to test, but requires the ability to articulate what "correct behavior" means as a property rather than a specific example.