Course contentsShow
← Software Engineering
Lesson 611 of 1,93319. Property-Based and Fuzz TestingFree lesson

Anatomy of a Property Test

Understanding the structure of property tests including generators, properties, and the test execution model.

Anatomy of a Property Test

You'll learn: How property tests are structured with generators, properties, and execution models to verify broad system behaviors.

Property-based tests have three essential components working together, like a factory production line that tests thousands of products automatically.

The Three Core Components

1. Generators
Generators produce random test inputs from your defined domain. Think of them as automatic input factories that create diverse test cases—integers, strings, lists, or complex objects—following rules you specify. Instead of writing test with 5, test with -1, test with 100 manually, the generator creates hundreds of varied inputs automatically.

2. Properties
Properties are the assertions about your code that should always be true, regardless of input. These are your universal rules: "reversing a list twice returns the original," "serializing then deserializing equals the original," or "sorting produces ascending order." Properties express invariants, not specific examples.

3. The Test Execution Model
The testing framework runs your property check repeatedly (often 100+ times by default) with different generated inputs. When a property fails, the framework shrinks the failing input to find the simplest case that breaks your code—turning [5, -923, 47, 0, 81] into just [-923] if negative numbers are the problem.

How They Work Together

The generator feeds random inputs to your property check. Each input runs through your code, and the property verifies the expected behavior holds. If any input violates the property, the framework halts, shrinks the input, and reports the minimal failing case. You get automatic discovery of edge cases without manual example enumeration.

Key Takeaway: Property tests consist of generators (creating inputs), properties (defining always-true assertions), and an execution model (running many iterations with automatic shrinking on failure).