Input Generation Strategies
What you'll learn: How property-based testing frameworks automatically generate a wide variety of test inputs from type information and rules you define.
The Core Idea
When you write a property test, you don't supply specific inputs — you describe what kind of inputs are valid, and the framework generates hundreds or thousands of examples automatically. This is like telling a robot chef "make me sandwiches with any bread, any protein, and any vegetable" instead of giving exact recipes. The framework explores the input space systematically, finding edge cases you'd never think to write by hand.
How Frameworks Generate Inputs
Property-based testing tools use generators — functions that produce random values of a given type. Most frameworks provide built-in generators for primitives (integers, strings, booleans) and can combine them to create complex data structures.
You can control generation through:
- Type specifications: "Give me integers" or "Give me lists of strings"
- Constraints: "Integers between 0 and 100" or "Non-empty lists"
- Combinators: Compose simple generators into complex ones ("pairs of username and email where email contains the username")
- Size parameters: Control how large/complex generated values become
Smart Generation Strategies
Frameworks don't just produce truly random data — they're biased toward interesting values. They automatically include edge cases like zero, empty collections, negative numbers, and boundary values. This combines randomness with strategic selection.
Key Takeaway: Property-based testing frameworks turn type definitions and constraints into automatic test input factories that explore your input space more thoroughly than hand-written examples ever could.