Pattern for generating negative Scalacheck scenarios: Using property based testing to test validation logic in Scala
We are looking for a viable design pattern for building Scalacheck Gen (generators) that can produce both positive and negative test scenarios. This will allow us to run forAll tests to validate functionality (positive cases), and also verify that our case class validation works correctly by failing on all invalid combinations of data. Making a simple, parameterized Gen that does this on a one-off basis is pretty easy. For example: def idGen(valid: Boolean = true): Gen[String] = Gen.oneOf(ID.values.toList).map(s => if (valid) s else Gen.oneOf(simpleRandomCode(4), "").sample.get) With the above