Unit testing methods that return futures in Scala is quite straightforward using ScalaTest 2.0+
12345678910111213
importorg.scalatest.FunSuiteimportorg.scalatest.concurrent.ScalaFuturesimportscala.concurrent.FutureclassNiceClass$TestextendsFunSuitewithScalaFutures{test("Test a method that returns a future"){valf:Future[Boolean]=somethingThatReturnsAFuture()whenReady(f){result=>assert(result)}}}
If your future is making a web service call or doing some sort of IO that takes a few seconds to complete, you might encounter an error like this one: