scala - 有没有办法模拟未作为服务参数接收的 WSClient - Scala + PlayFramework
问题描述
我有这项服务:
def doNext(token: String): Future[Location] = {
val config = getWsConfig(prefix)
ws.url(config.url)
.map(response => (response.json \ "location").get.asInstanceOf[JsString].value)
}
我正在尝试对其进行测试,但我无法模拟 WSClient,因为它不是该服务接收的参数。我怎么能测试这个?
这是我的测试 ATM
"Spec" should {
"giberish" in {
Server.withRouterFromComponents() { components =>
import Results._
import components.{ defaultActionBuilder => Action }
{
case GET(p"/do-next") =>
Action {
Ok(Json.arr(Json.obj("location" -> "USA")))
}
}
} { implicit port =>
WsTestClient.withClient { client =>
val user = buildUser()
val result = Await.result(instanceOf[ActionService].doAction("example-user_token")(user), 10.seconds)
result shouldBe "USA"
}
}
}
}
- 我知道它会失败,但我希望它失败,但我得到的只是:
java.net.ConnectException: Connection refused: localhost/0:0:0:0:0:0:0:1:8080
解决方案
推荐阅读
- python - Selenium - 保存 XLS 文件
- django - Django 动态表单字段 - 如何更改?
- apache-spark - Apache Spark + cassandra+Java +Spark 会话过滤记录基于给定 from 和 to 值之间的日期时间
- swagger - 如何在 swagger-ui.html 中隐藏选择规范
- excel - 删除链接到单元格的组合框
- angular - 使用 Validators.required True 的正确方法是什么?
- c# - ASP.NET WebAPI 方法只能在本地工作,但不能在 WebServer 上工作
- ios - 在 UIAlertController 中点击“确定”操作时如何关闭呈现视图控制器
- android-studio - Android Firebase 云功能-使用邮箱删除用户
- objective-c - AVAudioEngine 在 iOS14 中获取 inputNode 属性崩溃