英文:
Is there a way to add a descriptive Assert message in a Boolean ZIO Test
问题
我有一些要测试的布尔值,如下:
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
或者一般情况下有更好的测试布尔值的方法吗?
英文:
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?
答案1
得分: 6
是的!您可以在Assertion
或其符号别名??
上使用label
方法。
assert(g8Exists, isTrue ?? "g8Exists") &&
assert(projectExists, isTrue ?? "projectExists") &&
assert(testenvExists, isTrue ?? "testenvExists")
假设第一个断言失败,您将获得一个清晰的错误消息,指示失败的断言是哪一个。
false did not satisfy isTrue()
false did not satisfy (isTrue() ?? "g8Exists")
英文:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论