【发布时间】:2019-08-20 15:58:16
【问题描述】:
我观察到一种奇怪的行为。在我的一个测试用例中,我使用的是contentAsJson。在那个测试用例中,编译器并没有抱怨我必须为Timeout 和Materializer 提供一个implicit 值
class UserControllerUnitSpec extends PlaySpec with BeforeAndAfterAll with BeforeAndAfterEach with OneAppPerSuiteWithComponents{
..
"User signup request with body but with incorrect profile data " should {
"return error message " in {
...val resultFuture: Future[Result] = testEnv.controller.signupUser(request)
val responseBodyAsJsValue: JsValue = contentAsJson(resultFuture)//works
...
}
}
但在另一个测试用例中,编译器给出了我需要提供值的错误
class QuestionsControllerUnitSpec extends PlaySpec with BeforeAndAfterAll with BeforeAndAfterEach with OneAppPerSuiteWithComponents{
...
"newQuestion" should {
"should return error if the size of the body in the request is more than the maximum allowed size" in {
...
val response:Accumulator[ByteString,Result] = questionController.newQuestion(request)
val responseBody = contentAsJson(response)//(Timeout(Duration(5000,"millis")),testEnv.testEnv.mat).
...
}
我得到错误
Error:(1485, 39) could not find implicit value for parameter mat: akka.stream.Materializer
val responseBody = contentAsJson(response)//(Timeout(Duration(5000,"millis")),testEnv.testEnv.mat)
我如何调试为什么一个工作而另一个不工作?
更新 - 在马里奥的回答之后添加了返回类型。
【问题讨论】:
-
至少有礼貌地告诉你为什么这个问题被标记了!