I have a method that returns a Try
object:
def doSomething(p: SomeParam): Try[Something] = {
// code
}
I now want to test th
Just check to see that it is the success type with your return value:
maybeRes shouldBe Success("moo")
Another possibility is to do
import org.scalatest.TryValues._
maybeRes.success.value.bar shouldBe "moo"
This will give a message indicating the Try
was not a success, instead of throwing the exception in maybeRes.get
.
The analog exist for Option
, Either
and PartialFunction
(using the relevant import)
Alternatively
import org.scalatest.TryValues._
// ...
maybeRes.success.value should be "moo"