I am using ScalaTest to test Scala code. I am currently testing expected exceptions with code like this
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] } } }
But I would like to add an additional exception check, for example. I would like to verify that the exception message contains a specific line.
Is there a "clean" way to do this? Or do I need to use a catch try block?
scala exception testing scalatest
Jens schauder
source share