Repaso
EspaƱol
TestingAdvancedTST-11

What does property-based testing (e.g. Hypothesis) do?

Options

  1. It tests only the properties of each object
  2. It generates random inputs to check invariants (Correct option)
  3. It measures how much code coverage tests have
  4. 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.

Key terms

Practice this question in Repaso