While using scalacheck if we test any property with forAll then we only get reported failed test inputs and none passed test inputs.
scala> import org.scalacheck.Prop.forAll
scala> val propConcatLists = forAll { (l1: List[Int], l2: List[Int]) =>
l1.size + l2.size == (l1 ::: l2).size }
scala> propConcatLists.check
+ OK, passed 100 tests.
Is there any way to report all the random test inputs given by forAll to respective property test?
Use
collect
.This toy example illustrates its use:
The above code yields this output
Disclaimer: This toy example is clearly not a well designed property test. While it is definitely not true that an arbitrary pair of
Ints
never sums to 37, it passesScalaCheck
because the chances of two arbitraryInts
generated byScalaCheck
summing to 37 is pretty darn small. But if 37 were changed to any of -2, -1, 0, 1, or 2, the test would probably fail because the values -1, 0, and 1 are generated disproportionately frequently byScalacheck's
implicitarbitrary[Int]
generator.