Search code examples
unit-testingscalafuturespecs2playframework-2.2

Play 2.2 - specs2 - How to test futures in play 2.2?


my way of testing futures was using value1. I migrated to play2.2. I found out, my accustomed way to test is gone. @scala.deprecated("Use scala.concurrent.Promise instead.", "2.2")

Any help would be greatly appreciated.

Oliver


Solution

  • You can implement the PlaySpecification trait as described in the documentation. This trait provides a method await. You can also override the default timeout.

    import akka.util.Timeout
    import scala.concurrent.duration._
    
    class FooSpec extends PlaySpecification {
       override implicit def defaultAwaitTimeout: Timeout = 20.seconds
    
       "foo" should {
         "handle futures" {
            val result = await(Future(true))
    
            result should beTrue
         }
       }
    }