scenario("negative test that should throw a RuntimeException") {
try {
doSomething("anInvalidParameter")
fail("exception not thrown")
} catch {
case e: RuntimeException => //passes
}
}
the problem is that the scalatest fail() method throws a TestFailedException (which is an extension of a RuntimeException and not a AssumptionError). The ramifications of this is that this commonly written test pattern will always pass. This is because either the RuntimeException is thrown by the method being tested or a TestFailedException is thrown by the test and in both cases they are RuntimeExceptions. This is doubly bad because many developers who are writing tests implementing this sort of pattern will not realize that the test isn't effectively working since it will pass by default. They'd have to purposely test it against code that they know should not throw an error (like I did) to know there is an issue here.
The way to work around the scalatest class heirarchy flaw is to write the test like this:
scenario("negative test that should throw a RuntimeException") {
try {
doSomething("anInvalidParameter")
fail("exception not thrown")
} catch {
case e: TestFailedException => throw e
case e: RuntimeException => //passes
}
}
the problem here is that most developers won't realize the need to do this since it is a common fundamental plank in the java / scala community that test failures are Errors and not to be handled as Exception since test failures do not fall in the responsibility of an application to catch or handle. They truly need to live as Errors so that unexpected consequences like the scenario mentioned above do not happen!
--
You received this message because you are subscribed to the Google
Groups "scalatest-users" group.
To post to this group, send email to scalatest-users@googlegroups.com
To unsubscribe from this group, send email to
scalatest-users+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To post to this group, send email to scalate...@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/scalatest-users?hl=en
ScalaTest itself, and documentation, is available here:
http://www.artima.com/scalatest
---
You received this message because you are subscribed to the Google Groups "scalatest-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatest-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.