scalacontext-bound

could not find implicit value for evidence parameter of type org.scalacheck.Arbitrary


I was trying to use a method called random with the following signature:

def random[T: WeakTypeTag: Arbitrary]: T 

On a case class named Checking but I get this :

could not find implicit value for evidence parameter of type org.scalacheck.Arbitrary[com.organization.lambda.Checking]

I know this is due to some issues with context bounds, but I can't get my head around that and understand what has to be done.


Solution

  • Do you use random-data-generator-magnolia?

    If so, you should specify implicit value for Arbitrary[Checking] case class.

    Example from test source:

    implicit val arbitraryPerson: Arbitrary[Person] = Arbitrary {
      for {
        name <- Gen.oneOf("Daniela", "John", "Martin", "Marco")
        age <- Gen.choose(0, 100)
      } yield Person(name, age)
    }
    
    val instance = random[Person]
    

    Person is:

    case class Person(name: String, age: Int)