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

Reproducing and Seeding

Using seeds to replay specific test runs and reproduce failures deterministically during debugging.

Reproducing and Seeding

What you'll learn: How to use seeds to replay exact property-based test runs and deterministically reproduce failures when debugging.

The Randomness Challenge

Property-based testing generates random inputs to find edge cases. But what happens when a test fails? If you run it again, you get different random inputs—and the failure might disappear! This makes debugging frustrating, like trying to catch smoke.

Seeds: The Replay Button

A seed is a number that initializes the random number generator. Given the same seed, the generator produces the exact same "random" sequence every time. It's like setting your GPS to replay yesterday's drive—same turns, same route, guaranteed.

When a property test fails, the framework saves the seed that caused the failure. You can then re-run the test with that specific seed to reproduce the exact inputs that triggered the bug, making debugging deterministic and practical.

How It Works

Most property-testing frameworks automatically:

  1. Start each test run with a seed (random by default, or user-specified)
  2. Print the seed when reporting failures
  3. Let you pass a seed explicitly to replay a specific run

This turns "it failed once but I can't reproduce it" into "here's the exact seed—run it again and you'll see the same failure."

Why This Matters

Without seeding, property-based testing would be nearly unusable for debugging. You'd find bugs but couldn't reliably investigate them. Seeding bridges the gap between randomized exploration and the deterministic reproducibility developers need for debugging and regression testing.

Key Takeaway: Seeds let you replay exact property test runs by freezing the random input sequence, transforming mysterious failures into reproducible, debuggable scenarios.