How to show custom failure message in Specs2 (Scala)?

混江龙づ霸主 提交于 2019-12-10 02:52:06

问题


For example, for code like this:

myNum must beEqualTo("SOME INTERESTING TEXT")

The message will be like the following:

java.lang.Exception: ArrayBuffer() doesn't have size 1 but size 0

Is there an elegant way to get customised message displayed here?


回答1:


First you can name value you're testing.

myNum aka "meaningful name" must_== expectedValue

You can also overwrite the full message.

(myNum must_== expectedValue).setMessage("Full failure message")


来源:https://stackoverflow.com/questions/25351312/how-to-show-custom-failure-message-in-specs2-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!