@snoofle said:
@TheRubyWarlock said:Wow... so let's see. Unless I'm mistaken there are two possible outcomes, and both are shining examples of WTFery:
1) The code executes in the try block, and if no exceptions occur there's no assertions made, so the test passes... without actually asserting that things are what they should be.
2) If an exception occurs... it prints the exception to the console.. and asserts that True is True, so the test passes.
Now I've not used JUnit, but I've used NUnit. This seems to be as "effective" as not running any tests at all, since from the look of things it'll "pass" the test regardless of what happened.
Quite correct! 3,658 tests, all passing every single time. I've already found a couple via a random scan that will fail if these are removed and the exceptions allowed to occur.
Interesting aside about JUnit. If you try - catch some exception, that doesn't make the test fail (uncaught exceptions are considered failures). If you catch the exception, you actually need to do something to tell it to fail. For instance, sometimes you want to do:
try {
process_1_to_10(10);
// if it gets here, the test passed
} catch (OutOfRangeException o) {
assert(false); // should not have gotten exception
}
try {
process_1_to_10(11); // throws exception
assert(false); // expected exception not received
} catch (OutOfRangeException o) {
// test passes: got expected exception
}
The point is that they swallowed the exceptions, made useless assertions, and then made claims of how great it was!
That's why when I write tests, I don't wrap them in a try/catch block. This way, if there is an exception, the test will fail, just like if the condition I set out for it is not met.