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?

pme
  • 14,156
  • 3
  • 52
  • 95

1 Answers1

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")
Adam Fraser
  • 809
  • 5
  • 4