I hate writing tests, that's why I use Hypothesis

By Cheuk Ting Ho

Elevator Pitch

Ok, I lied, I still write tests. But instead of the example-based tests that we normally write, have you heard of property-based testing? By using Hypothesis, instead of thinking about what data I should test it for, it will generate test data, including boundary cases, for you.

Description

In this talk, we will explore what is property-based testing and why it can do a lot of heavy lifting in writing tests for us. As a contributor, I will introduce Hypothesis, a Python library that can help perform property-based tests with ease.

At the start of the talk, we will understand the power of property-based tests, what is it, how is it different from what we “normally do” - testing by example, and why is it useful in testing our code. This will be followed by demonstrations using Hypothesis. With a few examples, we will have a glimpse of how to create strategies - recipes for describing the test data you want to generate.

After that, we will also explore the Ghostwriters in Hypothesis which will actually write the test for you.

This talk is for Pythonistas who are new to property-based testing and found thinking of what parameters to use for testing a difficult task. This talk may provide them with a new approach to writing tests, which will be more efficient in some cases.

Notes

Details:

Property-based testing is not very popular in the Python community but yet it is a very powerful tool for testing codes thoroughly. If we test by example, we can miss testing out on edge cases. With Hypothesis, someone can create tests that will automatically cover all the edge cases as long as the assumption of the condition of the input is correct. It will make writing tests much easier and better.

In this talk, it will cover all the basics of Hypothesis and hopefully, it will help more developers approach testing in a more effective way.

Outline:

  • Introduction: 5 mins
  • What is property-based testing: 5mins
  • What is the difference between testing by example and property-based testing: 5mins
  • How to create a strategy: 5 mins
  • What is Ghostwriters in Hypothesis: 5 mins
  • Conclusion: 5 mins