【问题标题】:Adding scalacheck to specs2+spray-testkit example将 scalacheck 添加到 specs2+spray-testkit 示例
【发布时间】:2015-10-29 08:23:40
【问题描述】:

尝试将 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) ?
                        ^

这里发生了什么以及如何解决?

【问题讨论】:

    标签: spray specs2 scalacheck


    【解决方案1】:

    => 替换为箭头,而不是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}"
        }
      }
    }
    

    【讨论】:

    • 对不起,在错误信息中没有关闭卷曲,我的错误
    • 您可以尝试使用=> 代替unicode 字符 吗?
    • 是的!可能是 IDEA 做到了这一点。现在看起来更好,但现在在“in”关键字处:找不到 org.specs2.execute.AsResult[MyServiceSpec.this.RouteResult => ((Int, Int) => org.specs2.matcher 类型的证据参数的隐含值。 MatchResult[Any])]´
    • 我认为问题来自使用check。请参阅我编辑的答案。
    • 如何导入“道具”?它来自哪个命名空间?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2015-07-18
    • 1970-01-01
    • 2019-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多