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 ...

Get Scala Test-Driven Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.