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 | |
} | |
} | |
} |
futureValue
warps exceptions as TestFailedException
see https://gist.github.com/maowug/b0e3f564fc9c6290f3367a6650d194d2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Came here from your Google Groups thread. Adding a “me, too” here as a market in case one of us comes across a fix.
In my case, this expression:
Throws the expected exception, whereas:
Produces exactly the error you described.