Introduction to Property-Based Testing

a hands-on introduction to finding bugs with Hypothesis

Zac Hatfield Dodds

Best Practice Test Libraries (pytest/nose/...) Testing Tooling

See in schedule: Mon, Jul 26, 09:30-11:00 CEST (90 min)

Tests can be helpful: they can find bugs in new code, check for regressions in old code, and clarify precisely what the code is meant to do. But writing tests is tedious - and it's rare to think of an error when testing that you forgot when writing the code. My solution? Use tools that write tests for you!

In this tutorial, you'll learn the basic concepts of property-based testing, and how to apply them to find bugs real-world Python code using Hypothesis. We'll work through four blocks, each consisting of a short talk, live-coded demo, and extensive exercises for attendees:

1. Property-Based Testing 101: core concepts and the core of the Hypothesis library
2. Describe your Data: from numbers, to arrays, to recursive and more complicated things
3. Common Tests: from "does not crash" to "write+read == noop" to 'metamorphic relations'
4. Putting it into Practice: use what you've learned to find real bugs in a real project!

When we're done, you'll be able to apply Hypothesis with confidence - and find bugs in code from algorithms to business logic, whether you're a data scientist or web developer!

Type: Training (180 mins); Python level: Intermediate; Domain level: Intermediate

Zac Hatfield Dodds


Zac's modest goal is to help everyone write better code - mostly via bug-finding tools.

He spends his time working on Hypothesis, Pytest, and other open-source projects; along with HypoFuzz and his PhD at the Australian National University. And if you can't get to him via a computer, Zac can probably be found with a good book, a pile of chocolate, a long walk in the bush... or all three!