【问题标题】:Is there a way to add a descriptive Assert message in a Boolean ZIO Test有没有办法在布尔 ZIO 测试中添加描述性断言消息
【发布时间】:2020-04-21 21:36:06
【问题描述】:

我有几个 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

【问题讨论】:

  • 创建一个 ADT 而不是使用布尔值怎么样?
  • @MarioGalic 谢谢会做:)

标签: scala zio zio-test


【解决方案1】:

是的!为此,您可以在 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")

【讨论】:

  • @adam-fraser - 和往常一样,已经有一个很好的解决方案 - 谢谢;)
猜你喜欢
  • 1970-01-01
  • 2022-10-07
  • 1970-01-01
  • 2016-03-30
  • 2023-03-31
  • 1970-01-01
  • 2016-12-15
  • 2014-02-04
  • 1970-01-01
相关资源
最近更新 更多