Find Edge Cases with Property-Based Testing

8 steps · about 3 h 20 min · Intermediate

  1. Write a first generated test (guide, Hypothesis, 25 min)

    Generate varied inputs from a strategy and let the framework search beyond hand-picked examples.

  2. Think in invariants (guide, Hypothesis, 30 min)

    Replace a list of expected examples with a rule that should hold across an input space.

  3. Compose useful data strategies (reference, Hypothesis, 30 min)

    Build structured values whose generated cases remain valid and relevant to the behavior.

  4. Constrain data without hiding bugs (guide, Hypothesis, 25 min)

    Transform and filter generators carefully so difficult boundary cases still appear.

  5. Reproduce a discovered failure (reference, Hypothesis, 20 min)

    Use the examples database and explicit examples to make a failure repeatable.

  6. Remove flaky assumptions (guide, Hypothesis, 25 min)

    Control time, randomness and external state so generated tests remain deterministic.

  7. Tune test execution responsibly (reference, Hypothesis, 20 min)

    Set deadlines, example counts and health checks based on evidence rather than silencing warnings.

  8. Keep the minimal regression (guide, Hypothesis, 25 min)

    Translate the shrunk counterexample into a clear example test alongside the durable property.