私はScalaTestを使っていくつかのScalaコードをテストしています。 私は現在、このScalaTestを使用して予想される例外の追加プロパティをテストする方法
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]
}
}
}
のようなコードで期待の例外をテストしかし、私は、例えば、例外に追加のチェックを追加したいと思います例外メッセージに特定のStringが含まれていることを確認したいと思います。
これを行うには「きれいな」方法がありますか?または、try catchブロックを使用する必要がありますか?
val exception =
evaluating { throw new Exception("message") } should produce [Exception]
:
彼の構文:それは機能結果のために "べきである"のすべてと一致する。 –
''評価中 'は2.xで廃止され、3.xでは削除されました。非推奨のドキュメントは '代わりに[例外]をスローする必要があります'を使って助言します。しかし、3.0.0-M14は 'Assertion'を返します:' val ex:Assertion = an [例外]は投げられるべきです{throw new Exception( "boom")} '。 'Exception'をスローする方法はありますか? – kostja