问题描述
我正在使用Play 2.6.x,并且status(result)
的测试助手具有以下方法:def status(of: Accumulator[ByteString, Result])(implicit timeout: Timeout, 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())
当编译器找不到隐式值时,运行测试将抛出:could not find implicit value for parameter 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
什么是实现器-我假设它是Akka-HTTP的一部分
What is the Materializer -- I'm assuming it's part of Akka-HTTP
我该如何提供一个?
推荐答案
来自akka流文档:
Materializer
是基于Akka HTTP的Akka Streams的基石.您需要隐式解析其中之一以使测试编译.
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
的唯一可用实现.它是基于Akka actors 的Materializer
一个>.这就是为什么要创建一个,而又需要在范围内使用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:
implicit val sys = ActorSystem("MyTest")
implicit val mat = ActorMaterializer()
这篇关于Play Framework测试助手需要隐式`Materializer`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!