What does property-based testing (e.g. Hypothesis) do?
Options
- It tests only the properties of each object
- It generates random inputs to check invariants (Correct option)
- It measures how much code coverage tests have
- It records HTTP traffic in order to replay it
Answer
Generates many random inputs to check that invariants always hold, and shrinks failures to a minimal example
Why
Instead of writing examples one by one, you describe a rule that must ALWAYS be true, and the library tries hundreds of generated inputs, including nasty ones (empty, huge, unicode, negative).
Example rule: sorting twice gives the same result as sorting once, and keeps the same length.
When it finds a failure, it shrinks it to the smallest input that still fails, which makes debugging easy.
Remember
Property-based = test rules on many generated inputs.