问题描述
我正在使用 Play 2.6.x 并且 status(result)
的测试助手具有方法:def status(of: Accumulator[ByteString, Result])(隐式超时:超时,mat:Materializer):Int = status(of.run())
I'm using Play 2.6.x and the test helper for status(result)
has the method:def status(of: Accumulator[ByteString, Result])(implicit timeout: Timeout, mat: Materializer): Int = status(of.run())
当编译器找不到隐式值时,运行测试会抛出:找不到参数 mat 的隐含值:akka.stream.Materializer
Running tests throws when the compiler can't find the implicit value:could not find implicit value for parameter mat: akka.stream.Materializer
什么是 Materializer —— 我假设它是 Akka-HTTP 的一部分
What is the Materializer -- I'm assuming it's part of Akka-HTTP
我怎样才能提供一个?
推荐答案
来自 akka 流 文档:
From akka streams docs:
Materializer 是流执行引擎的工厂,它是使流运行的东西 [...]
Materializer
是 Akka Streams 的基石,Akka HTTP 在其上构建.您需要隐式解析其中之一才能编译测试.
The Materializer
is the cornerstone of Akka Streams, on which Akka HTTP is built on. You need one of these to be implicitly resolved to make your test compile.
目前 ActorMaterializer
是 Materializer
的唯一可用实现.它是一个 Materializer
基于 Akka 演员.这就是为什么要创建一个,您又需要在范围内拥有一个 ActorSystem
.
Presently the ActorMaterializer
is the only available implementation of Materializer
. It is a Materializer
based on Akka actors. This is the reason why, to create one, you need in turn to have an ActorSystem
in scope.
以下代码是您在测试中所需要的:
The following code is what you need in your test:
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
implicit val sys = ActorSystem("MyTest")
implicit val mat = ActorMaterializer()
这篇关于Play Framework 测试助手需要隐式`Materializer`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!