Contribute Media
A thank you to everyone who makes this possible: Read More

Property Based Testing in Python with Hypothesis


High unit-test coverage is great, but it cannot effectively find bugs triggered by interactions between multiple features. Since it is not scalable to write tests for all possible interactions, we turn to property-based testing - an approach where we generate tests instead of writing them. Property-based testing (PBT) is a random-testing approach that first became popular in the Haskell community as QuickCheck. It works by generating random examples to find minimal counterexamples to a pattern or law that ought to always hold true. PBT is especially useful in testing edge cases and interactions between multiple features, particularly in stateful systems. This talk introduces the principles of PBT along with its history and success stories. We then illustrate PBT patterns and examples in Python using Hypothesis. Finally, we see how it fits in with TDD and integration testing.


Improve this page