Saturday 11:30 a.m.–12:20 p.m.

Hypothesis: Tests That Write Themselves

David Kua

Audience level:
Intermediate

Description

Testing is generally seen as a Good Thing™ that one should do. Writing tests that are comprehensive and cover all possibilities however can be time-consuming, hard, or even downright impossible. Property-based testing is one method that can help with this. This talk will introduce the concept of property-based testing and how to do it yourself using the Python library Hypothesis.

Abstract

First we will learn about property-based testing. What it is, how it works, and why it is useful. Specifically we will be talking about how property-based testing can generate comprehensive test cases from properties that your code must have and then find the smallest counterexample that breaks your code. (10 minutes)

Second we will introduce you to Hypothesis the Python property-based testing library based off of Haskell's QuickCheck library. We will go over getting it set up and the basics of how to use it. (5 minutes)

Third we will go over properties of a piece of code. What constitutes a good and useful property, how to think of them, how to extract them from existing code, and how to write them out so that they can be used for tests. For this section we will be going through different practical Python examples using the Hypothesis library. (~20 minutes, the iteration of this talk from PyConCA had four increasingly more complex examples but I had to cut the last example short to fit within the 30 minute slot so I feel that this talk should be able to fit within 30 minutes again)

Finally the talk will finish off with more detailed resources on property-based testing, Hypothesis, other testing methods that an interested developer can use to make their test suite great again. (5 minutes but the resources don't have to be explained so could be cut to fit into the 30 minute slot)