我想测试WS客户端与服务器的假像它的播放2.4文档在这里解释真实:https://www.playframework.com/documentation/2.4.x/ScalaTestingWebServiceClients播放2.4 Scaldi WS测试
但我做DI与Scaldi,我不能够适应Play的文档代码使用Scaldi。
有人可以帮助我吗?
适应的代码大多是这种(来自播放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")
}
}
}
}
确定它的工作原理,但如果我不喜欢使用构造函数参数来做我的注入和只注入一些属性。 例如: **类GitHubClient(隐式INJ:进样器)延伸注射{ VAL WS =注入[WSClient] VAL的baseUrl =注入[字符串]( “的baseUrl”) ... } ** –
确定,这不应该是一个问题。您只需将它绑定到某个应用程序模块中,然后将其注入到测试中即可。 – tenshi