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
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
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
}
}
}
You can also override the default timeout for a single test scenario, like so:
import akka.util.Timeout
import scala.concurrent.duration._
class FooSpec {
"foo" should {
"handle futures" with DefaultAwaitTimeout {
override implicit def defaultAwaitTimeout: Timeout = 20.seconds
val result = await(Future(true))
result should beTrue
}
}
}
To stop your code at a specific position, use
Thread.sleep(milliseconds)
From play 2.4~, ,play.api.test.Helpers._
provides few utilities such as contentAsJson
, contentAsString
and contentAsBytes
which can be used if you are waiting for a Future
of type play.api.mvc.Result
. This takes care of the waiting but you still need to set the implicit timeout value.
© 2022 - 2024 — McMap. All rights reserved.