我正在使用scalatest和scalacheck来做一些基于属性的测试。我是scala和这些库的新手,所以假设这个代码实际上不那么难看。
我有这样的测试:
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
}
}
如何查看scalacheck生成的值?我目前正在进行这样的测试:
scala -cp "../lib/scalatest.jar:../lib/scalacheck.jar:." org.scalatest.run MyTests
但我得到的只是通过/失败输出。
答案 0 :(得分:1)
怎么样:
"My Class" should "Do something interesting" in {
check { (e1: String, e2: String, e3: String) =>
println(s"doInterestingThing($e1, $e2, $e3)")
doInterestingThing(e1, e2, e3)
}
}
作为旁注,原始代码中的这一行:
check((e1: String, e2: String, e3: String) => doInterestingThing(e1, e2, e3))
可以改写为:
check(doInterestingThing)