...

/

Generator-Driven Property Checking with ScalaCheck

Generator-Driven Property Checking with ScalaCheck

Learn how to use ScalaTest and ScalaCheck together.

In this lesson, we’ll take a look at the integration of ScalaCheck and ScalaTest to see how we can use ScalaCheck generators in a ScalaTest test suite. As usual, the first thing is to import the ScalaCheck integration.

Press + to interact
build.sbt
Dependencies.scala
object Dependencies {
object scalatestplus {
val `scalacheck-1-17` = "org.scalatestplus" %% "scalacheck-1-17" % "3.2.15.0"
}
}

The ScalaCheckPropertyChecks trait

The first thing we do is mix in the ScalaCheckPropertyChecks trait. It contains a number of methods called forAll to check our properties, as well as a method named whenever to evaluate a property only if some conditions on ...