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 framework. We can take advantage of this knowledge to generate random commands that we can issue on our stateful system.
For example, if our stateful system is a database, we can generate random commands to issue against this system. However, if the commands are random, how do we assert their effects on the ...