0
在ScalaTest中,是否可以在任意屬性上表達斷言,這些斷言不僅僅是對這些屬性的值進行簡單的等式比較?ScalaTest:對屬性的任意檢查
,而不是例如:
val list = List(1,2,3,4,5)
list.length should be < 4 // Fails with the unhelpful error message "5 is not less than 4"
case class Example(field: String)
val obj = Example("TEST")
obj.field should be allLowerCase // Given "allLowerCase", this fails without any information about obj.
我想這樣做如下:
val list = List(1,2,3,4,5)
list should have length < 4 // Fails with an error message containing the list
obj should have ('field (allLowerCase)) // Fails with an error message containing obj.
的目標是有關於與失敗的屬性的對象的有關情況在錯誤消息中如果匹配器失敗。
啊,對不起,我一直不清楚我的目標 - 我會更新問題。 – MHarris