Hi there,
On Fri, Aug 31, 2012 at 10:20 AM, Christian Johansen
<
chri...@cjohansen.no> wrote:
> No, it still treats other exceptions as an assertion failure. I'm not really
> convinced it should cause test errors?
I figured that might not be clear. What is important is not the
designation error or failure so much as debugging information or not
(which is associated with failure and error). Consider this scenario:
assert.exception(f, e);
There are three possibilities:
f throws e, all is as expected, test passes
f doesn't throw any exception, which isn't our expectation, test fails
and the possibility under discussion:
f throws a different exception
now if the test fails, I'll get a notice that I get a different
exception than was expected.
Now as the developer of 'f()' I need to debug this scenario. So I need
to find out why this wrong exception was thrown. But I only get a
failure report from buster now, which doesn't give me any clue as to
where the problem lies. It quite possibly has absolutely nothing to do
with the exception I *do* expect to be thrown and might be in a
different part of the code.
So what is my recourse? I can change the test temporarily to do this:
f()
and then I'll get a proper error traceback I can debug.
I wouldn't have to do this if buster considered this an error in the
first place and thus reported with a traceback. The exception I'm
getting quite possibly has nothing to do with the exception I'm
expecting. It isn't that I, developer of f(), accidentally threw the
*wrong* exception (that's certainly a possible scenario, but is it the
likely one?) it's that some other part of f() is broken and this
brokenness is revealed by an exception.
JavaScript is perhaps a bit misleading in this area in that "catch" is
catch-all always (ignoring for the moment the catch conditionals that
aren't universally supported). Let's consider a language where
specific catch is the recommended practice, such as Python. Its
default unit test framework has an 'assertRaises' like this
(considering the wrong exception an error):
http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises
One of the more advanced testing frameworks for the language, py.test,
has a slightly different behavior that at first sight looks like
buster's:
http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises
but it is redeemed for the debugging scenario because it actually does
give traceback information for the unexpected exception. So this could
also be resolved by changing the 'failure' handling to include
traceback information in case of an exception-triggered failure
instead of making this an error.
Regards,
Martijn