1

ここのPlay 2.4ドキュメントで説明されているように、偽のサーバーでWSクライアントをテストしたい: https://www.playframework.com/documentation/2.4.x/ScalaTestingWebServiceClients

しかし、私は Scaldi で DI を行っていますが、Scaldi を使用するように Play のドキュメント コードを適応させることができません。

誰かが私を助けることができますか?

適応するコードは主にこれです(Play docから来ます):

"GitHubClient" should {
  "get all repositories" in {

    Server.withRouter() {
      case GET(p"/repositories") => Action {
        Results.Ok(Json.arr(Json.obj("full_name" -> "octocat/Hello-World")))
      }
    } { implicit port =>
      WsTestClient.withClient { client =>
        val result = Await.result(
          new GitHubClient(client, "").repositories(), 10.seconds)
        result must_== Seq("octocat/Hello-World")
      }
    }
  }
}
4

2 に答える 2

2

ジュールズ

返信が遅くなりましたが、私はこれを自分で経験しました。ここでは、ScalaTest(Play Spec)、テスト サーバー、および wsUrl を使用した WSTestClient でテストする方法を示します。これはプレイ 2.5.4 用です。プロジェクトはこちら:reactive-rest-mongo

class UsersSpec extends PlaySpec with Injectable with OneServerPerSuite {

  implicit override lazy val app = new ScaldiApplicationBuilder()
    .build()

  "User APIs" must {

    "not find a user that has not been created" in {
      val response = Await.result(wsUrl("/users/1").get, Duration.Inf)
      response.status mustBe NOT_FOUND
      response.header(CONTENT_TYPE) mustBe None
      response.bodyAsBytes.length mustBe 0
    }
  }
}
于 2016-08-19T15:01:06.043 に答える