I\'d like to test a method that returns a Future
. My attempts were as follows:
import org.specs2.mutable.Specification
import scala.concurrent.Exec
Await is an anti pattern. Shouldn't ever use it.
You can use traits like ScalaFutures
, IntegrationPatience
, and Eventually
.
Example:
import org.specs2.mutable.Specification
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import scala.concurrent.Future
class AsyncWebClientSpec extends Specification with ScalaFutures
with IntegrationPatience{
"WebClient when downloading images" should {
"for a valid link return non-zero content " in {
whenReady(Future.successful("Done")){ testImage =>
testImage must be equalTo "Done"
// Do whatever you need
}
}
}
}