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.
Asked
Active
Viewed 1,596 times
5

Alexander Arendar
- 3,365
- 2
- 26
- 38
-
Duplicate of: https://stackoverflow.com/questions/44112671/how-to-test-a-tryt-with-scalatest-correctly – ncreep Jul 23 '17 at 01:27
-
1@ncreep the question you reference was posted later. Also solutions proposed there do not include a very simple and recommended by ScalaTest docs way described here. – Alexander Arendar Jul 24 '17 at 11:15
-
Sorry didn't notice the dates. In any case, I think that people stumbling upon this question may find the solution with the builtin `TryValues` there relevant (at least I did). – ncreep Jul 25 '17 at 15:55
1 Answers
5
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.

Alexander Arendar
- 3,365
- 2
- 26
- 38