I have a method that returns an object Try:
def doSomething(p: SomeParam): Try[Something] = {
// code
}
Now I want to test this with ScalaTest. I am currently doing it like this:
"My try method" should "succeed" in {
val maybeRes = doSomething(SomeParam("foo"))
maybeRes.isSuccess shouldBe true
val res = maybeRes.get
res.bar shouldBe "moo"
}
However, checking isSuccessfor truelooks a bit awkward, because for options and sequences there are things like should be(empty)and shouldNot be(empty). I can not find anything like it should be(successful).
Is this or is my approach really suitable?
source
share