Sunday, January 23, 2005

JUnit recipes

Was reading this book. Read a few chapters and came up with some weirdly interesting stuff.

The JUnit framework uses Errors to indicate if the Asserts Fail !! .. Not exceptions but Errors. An AssertionFailedError to be precise. For 2 reasons
- Errors are Unchecked
- We could have also used a unchecked exception, but then these are also thrown by the program that we are testing. So to differentiate who (the program or the test code) is actually throwing the unchecked exception JUnit throws an Error.

So basically there are 2 scenarios. We have an Assertion that has Failed and we have a program Error. The first is indicated by an Error being thrown by the JUnit framework and the second the program throwing an Exception.

Now the weird part is
the failing Assertion throws an Error but this is a Failure scenario from JUnits perspective
and Program Error throws an Exception but is a Error scenario from JUnits perspective

Striving to confuse :-)


Post a Comment

<< Home