【发布时间】:2011-05-13 08:48:14
【问题描述】:
我正在使用 ScalaTest 来测试一些 Scala 代码。 我目前使用这样的代码测试预期的异常
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers
class ImageComparisonTest extends FeatureSpec with ShouldMatchers{
feature("A test can throw an exception") {
scenario("when an exception is throw this is expected"){
evaluating { throw new Exception("message") } should produce [Exception]
}
}
}
但我想对异常添加额外检查,例如我想检查异常消息是否包含某个字符串。
有没有“干净”的方法来做到这一点?还是我必须使用 try catch 块?
【问题讨论】:
标签: exception testing scala scalatest