score:1

one possible solution would be to use intercept method:

val exception = intercept[nosuchelementexception] {
  list.empty[string].head // code that throws exception
}

exception.getmessage shouldbe "head of empty list"

score:1

you can you the "an [] should be thrownby" matcher:

 an [illegalargumentexception] should be thrownby {
    //code that should raise an exception here
 }

make sure your test class includes the "matchers":

class mytestclass extends funsuite with matchers 

Related Query

More Query from same tag