爲了測試我的代碼拋出預期例外,我使用的語法如下:ScalaTest thrownBy測試異常消息
an [IllegalArgumentException] should be thrownBy(Algorithms.create(degree))
有沒有什麼辦法來測試是否拋出異常包含預期的消息,如:
an [IllegalArgumentException(expectedMessage)] should be thrownBy(Algorithms.create(degree)) -- what doesn't compile
?
如何檢查消息的子字符串?將「the ... thrownBy ...」的結果賦值給val,然後使用常規匹配器? –