Search code examples
scalatest

ScalaTest: how to properly assert over Try values?


At the moment if I need to test that a value v of Try[T] type is Success(t) I do like: v.isSuccess shouldBe true I wonder if there are probably some better ways. For example, for Option[T] we can assert like: t shouldBe defined Probably there is something like this for Try[T] but I am not aware and searching the web does not help.


Solution

  • So far I came up with this solution: Based on this section of the ScalaTest docs we declare such symbol value: val successful = 'success and then assert like this:

    CampaignRowsPage.reserveInventory shouldBe successful
    

    Looks good to me.