Play Framework test helpers need implicit `Materializer`

后端 未结 3 1660
我寻月下人不归
我寻月下人不归 2021-01-06 11:36

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

相关标签:
3条回答
  • 2021-01-06 11:57

    there's also a status method in the form:

    def status(of: Future[Result])(implicit timeout: Timeout): Int
    

    make sure the controller return type is correct so the action returns a Future[Result]

    0 讨论(0)
  • 2021-01-06 12:02

    How about doing this:

    implicit val materializer = ActorMaterializer()
    
    0 讨论(0)
  • 2021-01-06 12:03

    From akka streams docs:

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

    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.

    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()
    
    0 讨论(0)
提交回复
热议问题