Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
Test design techniquesSeniorCommonTest design

How would you design useful generators and shrinking for a property-based test?

Answer

Model the valid and invalid input domains explicitly, bias generation toward boundaries and structurally interesting cases, and preserve relationships between dependent fields. A shrinker should reduce a failure toward the smallest case that still violates the property without breaking required structure. Record the seed and minimized example, and reject so few values that generation remains efficient and representative.

Strong answer includes

  • models dependent fields instead of generating them independently
  • targets boundaries and meaningful invalid data
  • keeps minimized counterexamples reproducible

Practical example

For a date-range generator, a naive implementation generates start and end independently and mostly produces invalid ranges where end precedes start; modeling end as start plus a generated duration keeps generated cases valid by construction while still covering same-day, cross-month and leap-year boundaries.

#property-based-testing#generators#shrinking#sdet

Sources

Hypothesis property-based testing documentationHypothesis · Property-based test design, generators, shrinking and reproducible counterexamples