Search code examples
scalaplayframeworkcontrollermockingexecutioncontext

Scala play Unit test controller 2.6.x - object Execution in package concurrent is deprecated: Please see 2.6 migration guide


Trying to follow the migration guide from Scala play framework version 2.6 as from: https://playframework.com/documentation/2.6.x/Highlights26

and after upgrading my tests are breaking:

val controller = new ProductController(stubControllerComponents().asInstanceOf[ProductControllerComponents])

I get:

> object Execution in package concurrent is deprecated: Please see
> https://www.playframework.com/documentation/2.6.x/Migration26#Execution

This is my controller declaration:

class ProductController @Inject()(cc: ProductControllerComponents)(implicit ec: ExecutionContext)
    extends ProductBaseController(cc)

and my injected execution context is "executionContext: scala.concurrent.ExecutionContext"

I'm following the official play framework 2.6 examples, but still test is not compiling throwing the error msg above.


Solution

  • See playframework/framework/src/play/src/main/scala/play/api/mvc/Controller.scala

      /**
       * The default execution context provided by Play. You should use this for non-blocking code only. You can do so by
       * passing it explicitly, or by defining an implicit in your controller like so:
       *
       * {{{
       *   implicit lazy val executionContext = defaultExecutionContext
       * }}}
       */
      def defaultExecutionContext: ExecutionContext = controllerComponents.executionContext