将 scalacheck 添加到 specs2+spray-testkit 示例
Adding scalacheck to specs2+spray-testkit example
尝试将 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) ?
^
这是怎么回事以及如何解决?
替换箭头的 =>
而不是 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}"
}
}
}
尝试将 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) ?
^
这是怎么回事以及如何解决?
替换箭头的 =>
而不是 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}"
}
}
}