Writing Properties

As we saw in our initial examples, part of property-based testing is generating data and the other part is coming up with properties. In this and the next sections, we’re going to focus on the latter.

The first thing to do when coming up with properties is to figure out what is the shape of valid inputs that our code works with. “Shape“ is not a technical term or a definition: we’re using it to describe the space of possible values that the input can be, such as all strings or all lists of integers. Figuring out the shape of valid inputs is where generators come into play in the context of property-based testing. If our code works with lists of integers, and therefore the shape of valid inputs is “lists of integers,” we can ...

Get Testing Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.