Why is my Scalacheck / Scalatest PropertyCheckConfig ignored?

I have a project with a lot of Scalacheck generators that receives a GeneratorDrivenPropertyCheckFailedException with the message "Received after 0 successful property ratings. 2 ratings were dropped."

I want him to try to evaluate it many more times, for example, 500 (by default), it would be fine, but I do not see that my setting is actually being redefined.

I added this code to the test class and I still get the same message. I tried sbt clean to make sure that something strange was not happening there.

implicit override val generatorDrivenConfig = PropertyCheckConfig(minSuccessful = 1, maxDiscarded = 500, workers = 1) 

Why is my Scalacheck / Scalatest PropertyCheckConfig ignored?

I am using Scalatest 2.2.1 with Scalacheck 1.12.1 with Scala 2.10.4

+8
scala testing scalatest scalacheck
source share
1 answer

If you filter the generator (for example, using suchThat ), the generator can generate a large number of values ​​that do not satisfy your suchThat restriction, and therefore discard them. I came across this when limiting the length of strings. One of the suggestions that I can give you is to try to create your Gen in a different way, in which you do not drop so many of them.

For example, here is what I meant to generate 4-character strings:

 val gen4CharString = Gen.listOfN(4, (Gen.listOfN[Char] suchThat (s => s != "" && s.length == 4))) 

This caused too many generated values ​​that were discarded, resulting in an error similar to the one you saw. Changing the generator, as shown below, fixed the problem.

 val gen4CharString = Gen.listOfN[Char] (4, Gen.alphaChar).map (_.mkString) 
+9
source share

All Articles