ConditionRacer
ConditionRacer

Reputation: 4498

How to see the values that scalacheck is generating?

I am using scalatest and scalacheck to do some property based testing. I'm new to both scala and these libraries so pretend this code is much less ugly that it actually is.

I have a test like this:

class MyTests extends FlatSpec with Checkers {

  "My Class" should "Do something interesting" in {
    check((e1 : String, e2 : String, e3 : String) =>
      doInterestingThing(e1, e2, e3))
   }

  def doInterestingThing(e1: String, e2: String, e3: String) : Boolean = {
    val myClass = new MyClass[String]
    val passed = myClass.Foo(e1, e2, e3)
    passed
  }
}

How do I see the values that scalacheck is generating? I'm currently running the test like this:

scala -cp "../lib/scalatest.jar:../lib/scalacheck.jar:." org.scalatest.run MyTests

But all I get is pass/fail output.

Upvotes: 1

Views: 273

Answers (1)

Erik Kaplun
Erik Kaplun

Reputation: 38217

How about:

"My Class" should "Do something interesting" in {
  check { (e1: String, e2: String, e3: String) =>
    println(s"doInterestingThing($e1, $e2, $e3)")
    doInterestingThing(e1, e2, e3)
  }
}

As a side note, this line in your original code:

check((e1: String, e2: String, e3: String) => doInterestingThing(e1, e2, e3))

could be rewritten as:

check(doInterestingThing)

Upvotes: 1

Related Questions