Topic

Intro to Property-Based Testing with Hypothesis
By: Paul Zuradzki
Date: April 11, 2024, 6 p.m.

One shortfall of example-based unit tests is that they only test known examples. Property-based testing lets you test against randomized inputs if you can specify properties that must be true of the code's behavior ("invariants"). You also test your function against extreme-values (aka, fuzzing).

In this talk, will review some examples of property-based tests using the Hypothesis library. We will demo automated test generation ("ghostwriting" tests) to make writing tests easier. We will demo stateful testing to confirm that all possible states are valid in a program.  Lastly, we will end with parting thoughts on how to specify properties. Often, the tricky part with PBT is knowing what to test! Since we are using randomized input, we need to specify properties that should hold true across all outputs.