mardi 27 octobre 2015

scalacheck case class random data generator

I'm trying to generate random data with Scalacheck. I have a hierarchy of case classes with many properties. The only way I've found so far to populate the case classes is like this :

case class Data(a: String,
                b: String,
                c: String)

val genLigneDecompte: Gen[Data] = for {
  ag <- Gen.alphaStr
  bg <- Gen.alphaStr
  cg <- Gen.alphaStr
} yield Data(
    a = ag,
    b = bg,
    c = cg
  )

For a case class with 10-20 properties it's pretty tedious. I was wondering if there was a way to automate it somehow...

Aucun commentaire:

Enregistrer un commentaire