是否有成语为ScalaTest匹配器添加线索,以使该线索成为断言失败的一部分?我知道我目前可以这样编写一个ScalaTest断言:
withClue("expecting a header row and 3 rows of data") {
rowCount should equal(4)
}
这是将线索添加到断言的唯一语法吗?能够写一个断言看起来像这样会很好:
rowCount should equal(4) because("expecting a header row and 3 rows of data")
最佳答案
如果混入AppendedClues
,则可以将withClue
写为后缀:
class TestSuite extends FlatSpec with Matchers with AppendedClues {
3 should equal(4) withClue("expecting a header row and 3 rows of data")
}
当然也可以不带括号地工作。
关于scala - 是否有为ScalaTest匹配器添加线索的语法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28307155/