How to show custom failure messages in ScalaTest?

后端 未结 3 714
無奈伤痛
無奈伤痛 2021-01-31 13:29

Does anyone know how to show a custom failure message in ScalaTest?

For example:

NumberOfElements() should equal (5)

Shows the followin

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 13:43

    You can also use withClue without importing anything or adding it to the test class:

    withClue(s"Expecting distinct elements: ${elements.toList}") { elements.length shouldBe 3 }
    

    This is imported from Assertions class: org.scalatest.Assertions#withClue

提交回复
热议问题