vendredi 2 janvier 2015

scala specs2 testing scala Future

I am new to Spces2 testing framework and I am strugling with testing a function which returns a a scala future. My attempts were as follows



import org.specs2.mutable.Specification
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}

class AsyncWebClientSpec extends Specification{

"WebClient when downloading images" should {
"for a valid link return non-zero content " in {
val testImage = AsyncWebClient.get("http://ift.tt/1xnZOML")
testImage.onComplete{
res => res match {
case Success(image) => image must not have length(0)
case _ =>
}
AsyncWebClient.shutDown
}
}
}
}


Apart from the fact that I am unable to make this code work I guess that there could be a better way of testing a futures e.g. some Future matcher as I found for play framework but I am not using Play in the project.


What is the best practice in this scenario?


Thanks for helping me out


Aucun commentaire:

Enregistrer un commentaire