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

Generators and Input Domains

Learning how property-based testing frameworks generate diverse test inputs across the entire valid input space.

Generators and Input Domains

You'll learn: How property-based testing frameworks automatically produce a wide variety of test inputs to explore your code's behavior across the entire valid input space.

The Core Idea

In property-based testing, you don't manually write specific test cases. Instead, you describe what kinds of inputs are valid, and the framework automatically generates hundreds of diverse examples to test your property. This process relies on generators — specialized functions that produce random values within a defined input domain.

Think of it like this: instead of hand-picking 5 specific fruits to test if your sorting algorithm works, you describe "any list of comparable items" and let the framework generate thousands of different lists — empty ones, single items, sorted lists, reverse-sorted lists, duplicates, huge lists — all automatically.

How It Works

A generator knows how to create random instances of a type. The framework provides built-in generators for common types (integers, strings, lists) and lets you combine them to describe complex inputs.

The input domain is the complete set of all valid inputs your function should handle. For example:

  • Integers between -100 and 100
  • Non-empty lists of strings
  • Valid email addresses
  • Binary trees with up to 50 nodes

By defining the input domain clearly, you ensure the generator explores edge cases you might never think to write manually: very small values, very large values, empty collections, boundary conditions, and unusual but valid combinations.

The framework runs your property test many times (typically 100-1000+), each time with different generated inputs, searching for failures across the entire domain.

Key Takeaway: Generators automatically produce diverse test inputs across your entire valid input domain, catching edge cases and unusual scenarios you'd likely miss when writing examples by hand.