13

I have a project with a lot of Scalacheck generators that is getting a GeneratorDrivenPropertyCheckFailedException with the message "Gave up after 0 successful property evaluations. 2 evaluations were discarded."

I want to have it try to evaluate it many more times like 500 (the default) would be fine, but I'm not seeing my configuration override actually being used.

I added this code to the test class and I'm still getting the exact same message. I've tried 'sbt clean' just to make sure something weird wasn't happening there.

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

Why is my Scalacheck/Scalatest PropertyCheckConfig being ignored?

I'm using Scalatest 2.2.1 with Scalacheck 1.12.1 with Scala 2.10.4

myyk
  • 1,471
  • 15
  • 32

1 Answers1

19

If you are filtering the generator (for instance, by using a suchThat), the generator can be creating a large number of values that don't satisfy your suchThat constraint and are therefore getting discarded. I've run into this when I constrain the length of strings. The one suggestion I can give you is to try and create your Gen a different way where you aren't discarding so many of them.

For example, here is what I first had for generating 4-character strings:

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

This was causing too many generated values to be discarded, resulting in an error similar to the one you were seeing. Altering the generator like below eliminated the problem.

val gen4CharString = Gen.listOfN[Char] (4, Gen.alphaChar).map (_.mkString)
Ram Rajamony
  • 1,571
  • 13
  • 17
  • 1
    Extremely helpful tip. Ran into this problem generating strings of no greater than a certain length with `Gen.alphaNumStr.suchThat(_.length <= 50)` and resolved with `Gen.choose(0, 50).map(Gen.listOfN(_, Gen.alphaNumChar)).map(_.mkString)`. – Michael Ahlers Oct 23 '17 at 16:57