ScalaCheck is a property based testing library that automate testcases on properties specified by the programmer.
Documentation:
forAllorg.scalacheck.Prop.forAll
forAll helps us create universial quantified properties.
It takes a function that should return a boolean. The function takes parameters of any type, as long as there exist an implicit Arbitrary instance of its types.
GeneratorCheck generates random instances of the function paramters, but we can also explicitly define how to generate the test data using Gen.
import org.scalacheck._
val smallInteger = Gen.choose(0,100)
val propSmallInteger = Prop.forAll(smallInteger) { n =>
n >= 0 && n <= 100
}
Here the forAll method will ensure to test all the numbers from 0 to 100, inclusively.
Gen can help gain better control over the ranges of numbers that we test our properties with.
Arbitrary