尝试将scalacheck添加到spray-testkit + specs2示例中: 以下路线提供服务:
def myRoute = get(
path("add" / IntNumber / IntNumber) ((a, b) =>
complete((a+b).toString)
)
)
及其测试规范:
"MyService" should {
"do calculation" in {
Get("/add/30/58") ~> myRoute ~> check {
responseAs[String] === "88"
}
}
"do calculation with scalacheck" in {
check { (a: Int, b: Int) ⇒
Get(s"/add/$a/$b") ~> myRoute ~> check {
responseAs[String] === s"${a+b}"
}
}
}
}
应该很简单,但我的大脑不允许制定第二个测试用例。我得到像
这样的错误...MyService.Spec.scala:44: not found: value a"
check { (a:Int, b:Int)
^
...MyService.Spec.scala:44: value ? is not a member of (Int, Int)
check { (a:Int, b:Int) ?
^
这里有什么,以及如何解决?
答案 0 :(得分:2)
替换箭头的=>
而不是unicode字符⇒
。
然后你应该使用prop
代替check
并写下:
"do calculation with scalacheck" in {
prop { (a: Int, b: Int) =>
Get(s"/add/$a/$b") ~> myRoute ~> check {
responseAs[String] === s"${a+b}"
}
}
}