6

我有几个Booleans我想测试,比如

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

如果失败了,我得到的只是:

false did not satisfy equalTo(true)

不知道哪条线失败了。有没有办法可以添加描述性断言消息。例如:

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

或首选:

assertTrue(g8Exists, "g8Exists")

会导致

false did not satisfy equalTo(true) - g8Exists

还是有更好的测试方法Booleans

4

1 回答 1

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")
于 2020-01-03T13:56:46.423 回答