Play Framework 测试助手需要隐式的`Materializer`
Play Framework test helpers need implicit `Materializer`
我正在使用 Play 2。6.x status(result)
的测试助手有以下方法:
def status(of: Accumulator[ByteString, Result])(implicit timeout: Timeout, mat: Materializer): Int = status(of.run())
运行 测试在编译器找不到隐式值时抛出:
could not find implicit value for parameter mat: akka.stream.Materializer
什么是 Materializer -- 我假设它是 Akka-HTTP 的一部分
我怎样才能提供一个?
这样做怎么样:
implicit val materializer = ActorMaterializer()
表单中还有一个状态方法:
def status(of: Future[Result])(implicit timeout: Timeout): Int
确保控制器 return 类型正确,以便操作 return 成为 Future[Result]
来自 akka 流 docs:
The Materializer is a factory for stream execution engines, it is the
thing that makes streams run [...]
Materializer
是 Akka Streams 的基石,Akka HTTP 就是在其上构建的。您需要隐式解析其中之一才能使您的测试编译。
目前 ActorMaterializer
是 Materializer
的唯一可用实现。它是基于 Akka actors 的 Materializer
。这就是为什么要创建一个,你需要在范围内有一个 ActorSystem
。
以下代码是您在测试中需要的代码:
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
implicit val sys = ActorSystem("MyTest")
implicit val mat = ActorMaterializer()
我正在使用 Play 2。6.x status(result)
的测试助手有以下方法:
def status(of: Accumulator[ByteString, Result])(implicit timeout: Timeout, mat: Materializer): Int = status(of.run())
运行 测试在编译器找不到隐式值时抛出:
could not find implicit value for parameter mat: akka.stream.Materializer
什么是 Materializer -- 我假设它是 Akka-HTTP 的一部分
我怎样才能提供一个?
这样做怎么样:
implicit val materializer = ActorMaterializer()
表单中还有一个状态方法:
def status(of: Future[Result])(implicit timeout: Timeout): Int
确保控制器 return 类型正确,以便操作 return 成为 Future[Result]
来自 akka 流 docs:
The Materializer is a factory for stream execution engines, it is the thing that makes streams run [...]
Materializer
是 Akka Streams 的基石,Akka HTTP 就是在其上构建的。您需要隐式解析其中之一才能使您的测试编译。
目前 ActorMaterializer
是 Materializer
的唯一可用实现。它是基于 Akka actors 的 Materializer
。这就是为什么要创建一个,你需要在范围内有一个 ActorSystem
。
以下代码是您在测试中需要的代码:
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
implicit val sys = ActorSystem("MyTest")
implicit val mat = ActorMaterializer()