Learn Python with Talk Python's 270 hours of courses

Property-based Testing with Hypothesis

Episode #67, published Wed, Jul 13, 2016, recorded Mon, Jul 11, 2016

Let's talk about your unit testing strategy. How do you select the tests you write or do you even write tests? Typically, when you write a test you have to think of what you are testing and the exact set of inputs and outcomes you're looking for. And there are strategies for this. Try to hit the boundary conditions, the most common use-cases, seek out error handling and so on.

We all do this to varying degrees of success. But we if we didn't have to do this. What if there was some kind of way to express the relationship between inputs and outputs but your tests could explore the problem space themselves?

Well, there is a way and it's called property-based testing. This week you'll learn about Hypothesis, the most popular property based testing system created by David MacIver.

Links from the show:

Hypothesis framework: hypothesis.works
Hypothesis on github: github.com/HypothesisWorks/hypothesis-python
Matt Bachmann - Better Testing With Less Code at PyCon:
David on the web: drmaciver.com

Want to go deeper? Check out our courses

Talk Python's Mastodon Michael Kennedy's Mastodon