考虑通过线索提供有关失败的自定义信息,例如,
assert(userId != "", myCustomInformation)
或者
withClue(myCustomInformation) {
userId should not be empty
}
customInformation
比如说,可能在哪里
case class MyCustomInformation(name: String, id: Int)
val myCustomInformation = MyCustomInformation("picard", 42)
这是一个工作示例
import org.scalatest._
class ClueSpec extends FlatSpec with Matchers {
case class MyCustomInformation(name: String, id: Int)
"Tests failures" should "annotated with clues" in {
withClue(MyCustomInformation("picard", 42)) {
"" should not be empty
}
}
}
哪个输出
[info] Tests failures
[info] - should annotated with clues *** FAILED ***
[info] MyCustomInformation(picard,42) "" was empty (HelloSpec.scala:10)
有关自定义报告器的示例,请考虑https://stackoverflow.com/a/56790804/5205022