O'Reilly logo

Scala Test-Driven Development by Gaurav Sood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generator-driven properties

Sometimes, we want our properties to be checked against a randomly generated set of inputs. These input values are generated within some bounds that we can define with conditions. One example is, when we have a compression algorithm that needs testing. Instead of using a predefined list of strings, we can have a generated set of strings so that our function is tested against them.

Generator-driven property tests make use of ScalaCheck; therefore, make sure ScalaCheck JAR is included in the classpath. Your test will need to mixin GeneratorDrivenPropertyCheck. If your test uses both table-driven property checks and Generator-driven property checks, then mixin trait PropertyChecks as it extends both TableDrivenPropertyChecks ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required