Property-based testing with Hypothesis in Python

12 steps · about 5 h 5 min · Intermediate

  1. Quickstart - Hypothesis documentation (doc, Hypothesis official docs, 10 min)

    Run your first @given test and see Hypothesis generate 100 inputs for you.

  2. Introduction to Hypothesis (doc, Hypothesis official docs, 15 min)

    Explains what a run does and when property-based testing adds to unit tests.

  3. Getting Started With Property-Based Testing in Python With Hypothesis and Pytest (tutorial, Semaphore, 30 min)

    A worked gcd example shows how a failing case like 0, 0 exposes a bug and how to write more complete properties.

  4. Built-in strategies - Hypothesis documentation (doc, Hypothesis official docs, 15 min)

    Learn the building blocks (integers, text, lists, builds, one_of) that describe valid input.

  5. A Beginner's Guide to Unit Testing with Hypothesis (guide, Better Stack, 25 min)

    Adds assume(), example() and settings, so you can constrain inputs without hiding bugs.

  6. Python Hypothesis: Property-Based Testing Guide (article, Universo Python, 20 min)

    Shows idempotence and sorting properties, and why constraints should model the real domain.

  7. Escape from auto-manual testing with Hypothesis! (video, Zac Hatfield-Dodds, PyCon AU 2018, 30 min)

    A talk by a Hypothesis maintainer on common tactics and how minimal failing examples are found.

  8. Custom strategies - Hypothesis documentation (doc, Hypothesis official docs, 20 min)

    Once built-ins fall short, write strategies for your own domain data.

  9. Let Hypothesis Break Your Python Code Before Your Users Do (article, Towards Data Science, 25 min)

    Applies round-trip tests, reference-implementation checks and stateful classes to realistic code.

  10. SE Radio 589: Zac Hatfield-Dodds on Property-Based Testing in Python (video, Software Engineering Radio, 1 h)

    A long conversation on adoption, pytest integration and the challenges of property-based testing.

  11. Strategies Reference - Hypothesis documentation (reference, Hypothesis official docs, 20 min)

    Browse it to find strategies for dates, regexes, numpy, pandas and grammars when you need them.

  12. Sufficiently Advanced Testing (video, Zac Hatfield-Dodds, PyCon AU 2019, 35 min)

    Covers fuzzing, how shrinking works and newer techniques. The page links to the YouTube video and a transcript.