为了测试我的代码抛出预期例外,我使用的语法如下: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,然后使用常规匹配器? –