【问题标题】:Play Framework 2.2 - functional test fails with type mismatchPlay Framework 2.2 - 功能测试因类型不匹配而失败
【发布时间】:2013-10-07 16:32:54
【问题描述】:

我刚刚升级到 Play 2.2,由于 Helpers 已更改,我的测试不再编译。

import org.specs2.mutable.Specification

import play.api.test._
import play.api.test.Helpers._

import play.api.libs.ws._
import play.api.mvc.Results._

class ApplicationSpec extends Specification {
  import controllers._

  "Application" should {

    "test WS logic" in new WithServer {
      await(WS.url("http://localhost:3333").get()).status must equalTo(OK)
    }

  }
}

给出以下编译错误

type mismatch;
[error]  found   : scala.concurrent.Future[play.api.libs.ws.Response]
[error]  required: org.specs2.matcher.Matcher[?]

【问题讨论】:

    标签: playframework-2.2


    【解决方案1】:

    这只是play.api.test.Helpers.awaitorg.specs2.matcher.FutureMatchers.await 之间的名称冲突。

    您可以更明确地引用播放助手(或重命名您的导入):

    Helpers.await(WS.url("http://localhost:3333").get()).status must equalTo(OK)
    

    以下可能更好,但是,尚未将其写入文档:

    https://github.com/playframework/playframework/blob/master/framework/src/play-test/src/main/scala/play/api/test/PlaySpecification.scala

    因此,只需在您的测试中扩展 PlaySpecification 而不是 Specification

    import org.specs2.mutable.Specification
    
    import play.api.test._
    import play.api.test.Helpers._
    
    import play.api.libs.ws._
    import play.api.mvc.Results._
    
    class ApplicationSpec extends PlaySpecification {
      import controllers._
    
      "Application" should {
    
        "test WS logic" in new WithServer {
          await(WS.url("http://localhost:3333").get()).status must equalTo(OK)
        }
    
      }
    }
    

    【讨论】:

    • 我认为第一个代码示例应该是 Helpers.await(...)
    猜你喜欢
    • 2020-05-27
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多