Stateful Property-Based Testing

Get introduced to stateful property-based testing.

Until now, we’ve mostly looked at property-based testing in the context of testing pure, stateless functions that take an input and return an output. However, property-based testing is also useful for testing stateful systems.

What is the stateful system?

A stateful system is a system that, well, carries the state. For example, a database is a stateful system.

In our examples so far, we only used property-based testing to generate some data and then feed it to a piece of code and assert the result of that. With stateful systems, things change: we now have to deal with setting a state and only executing some operations when the system is in a given state. Let’s see how we can use property-based testing for something like that.

Modeling the Stateful System

We know how to generate random data through our property-based testing ...