Created
September 25, 2015 16:30
-
-
Save anonymous/04158ab2b087dab7288c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name:="futures-test" | |
scalaVersion:="2.11.7" | |
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package future_test | |
import scala.concurrent.{ExecutionContext, Future} | |
object ExampleCode { | |
def execute()(implicit ec: ExecutionContext): Future[String] = { | |
Future { throw new TestException("Some data") } | |
} | |
} | |
class TestException(data: String) extends RuntimeException("Expected in test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package future_test | |
import org.scalatest.concurrent.ScalaFutures | |
import org.scalatest.{ShouldMatchers, WordSpec} | |
class ExampleTest extends WordSpec with ShouldMatchers with ScalaFutures{ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
".futureValue when Future contains an exception" should { | |
"allow to test on that exception class" in { | |
a[TestException] should be thrownBy(ExampleCode.execute().futureValue) | |
} | |
"allow to test on RuntimeException" in { | |
ExampleCode.execute().futureValue | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
futureValue
warps exceptions asTestFailedException
see https://gist.github.com/maowug/b0e3f564fc9c6290f3367a6650d194d2