Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to add a descriptive Assert message in a Boolean ZIO Test

I have a couple of Booleans I want to test, like

assert(g8Exists, equalTo(true)) &&
assert(projectExists, equalTo(true)) &&
assert(testenvExists, equalTo(true)) ...

If one fails, all I get is:

false did not satisfy equalTo(true)

No clue which line failed. Is there a way I can add a descriptive Assert message. For example:

assert(g8Exists, equalTo(true), "g8Exists")

Or preferred:

assertTrue(g8Exists, "g8Exists")

Would result in

false did not satisfy equalTo(true) - g8Exists

Or is there a better way to test Booleans in general?

like image 853
pme Avatar asked Jan 03 '20 10:01

pme


1 Answers

Yes! You can use the label method on Assertion or its symbolic alias ?? for this.

assert(g8Exists, isTrue ?? "g8Exists") &&
assert(projectExists, isTrue ?? "projectExists") &&
assert(testenvExists, isTrue ?? "testenvExists")

Assuming that the first assertion fails you would get a nice error message indicating exactly which assertion failed.

false did not satisfy isTrue()
false did not satisfy (isTrue() ?? "g8Exists")
like image 176
Adam Fraser Avatar answered Oct 08 '22 09:10

Adam Fraser