Play Framework测试助手需要隐式`Materializer` [英] Play Framework test helpers need implicit `Materializer`

查看:63
本文介绍了Play Framework测试助手需要隐式`Materializer`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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是流执行引擎的工厂,它是 使流运行的事物[...]

The Materializer is a factory for stream execution engines, it is the thing that makes streams run [...]

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.

当前,ActorMaterializerMaterializer的唯一可用实现.它是基于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`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆