← Reference · Nestor G Pestelos Jr · Print this page

Software Engineering · Testing

Property-Based Testing

Reference entry · last updated 20260908

Property-based testing checks rules about program behavior across generated inputs. A testing library supplies examples drawn from an input strategy and looks for a case that violates the rule.[1]

First principles and definitions

A property states a rule expected to hold for a defined input domain. An input strategy describes how examples are generated. The test applies the program to each example and checks the rule.

An illustrative property

For an integer sorting function, the output should be ordered and contain the same values with the same counts as the input. Checking only ordering would miss a broken function that always returns an empty list.

Hypothesis can generate examples and simplify a failing example, a process called shrinking, to help explain the failure.[1]

Limits and complementary checks

Finite generated tests cannot establish a rule for every possible input. Weak properties, narrow strategies, or missing environmental conditions can leave defects undetected.

Example-based tests preserve specific cases. Mutation testing asks whether tests detect deliberate changes to the code. These techniques answer different questions.

See also

References

  1. Hypothesis project. Hypothesis documentation.