Checking Stateful Properties with ScalaCheck

Learn how to test properties on stateful components with ScalaCheck and ScalaTest.

In this lesson, we’ll see how to test mutable or stateful components using ScalaCheck. Even if immutable components are often easier to use and understand, our applications sometimes need to use mutable components. Some components in Scala might look immutable to their users, but internally their implementation might make use of a mutable state.

With ScalaCheck we can test the behavior of a mutable component. In other words, we can see how the methods affect the state of the component over time. ScalaCheck defines a library to model commands that we can use to ensure the validity of our properties.

Modeling method invocation through commands

Modeling commands in ScalaCheck can be complex. In this lesson, we’ll test the following implementation of MutableEducative.

Get hands-on with 1200+ tech skills courses.