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

1

6

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?

Grandpa answered 3/1, 2020 at 10:5 Comment(2)
How about creating an ADT instead of using booleans?Foredate
@MarioGalic thanks will do:)Grandpa
E
6

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")
Elea answered 3/1, 2020 at 13:56 Comment(1)
@adam-fraser - and as always there is already a nice solution - thanks;)Grandpa

© 2022 - 2024 — McMap. All rights reserved.