Using the "should NOT produce [exception]" syntax in ScalaTest
This is not possible directly in the latest version of ScalaTest because the method should
of EvaluatingApplicationShouldWrapper
does not have an overload that takes a NotWord
, only one that takes a ResultOfProduceInvocation[T]
.
I'd suggest just letting the undesired exception happen, which will fail the test. This is the classic way.
But if you feel you need more clarity about what failed exactly, you could use a try
-catch
block to handle the error. If you catch the error you don't want to happen, handle the exception with a call to the fail
method:
fail("That expression shouldn't have thrown a MyExceptionType exception")
The current version of ScalaTest does support this:
noException should be thrownBy 0 / 1
See docs.