Using the "should NOT produce [exception]" syntax in ScalaTest

Guillaume Belrose picture Guillaume Belrose · Aug 9, 2011 · Viewed 13.4k times · Source

I'am toying with Specs2 and ScalaTest for BDD in Scala. I've written expectations in Specs2 when I am asserting that a given exception should not be thrown.

"do something" in {
 {
   ....
 } must not(throwA[MyException])
}

I was hoping to be able to write the equivalent in ScalaTest like:

"do something" in {
 evaluating {
   ....
 } should not produce[MyException]
}

But this does not compile and I could not find way of doing it. Is that even possible?

Many thanks in advance.

Answer

Wolfram Arnold picture Wolfram Arnold · Jan 7, 2016

The current version of ScalaTest does support this:

noException should be thrownBy 0 / 1

See docs.