When a test fails, Junit throws an java.lang.AssertionError
same as when java build-in assert statement fails.
So if you have assertions in your code,
be ready for surprises.
Assertion in my code is :
assert timeout > 0;
my test is passing whether or not timeout > 0
can you see the problem :
@Test
public void constructor_invalid_timeout() {
long timeout = -1;
try {
new AbstractInquiry(timeout){
@Override
protected Object getResponse() {
return null;
}
@Override
protected void progress_hook() {
//no progress
}
};
// ********* FROM HERE *****************
fail("assertion failed : timeout > 0");
}
catch (AssertionError e) {
}
// ********* TO HERE *****************
}
JUnit throws an AssertionError which its not defined by JUnit.
( so it’s not reserved to JUnit. )
Even further :
Is it safe, a testing framework throw any kind of Exceptions or Errors ?
Note:
I know it’s disapproved to use ‘assert’ statements validating public method arguments.
but it’s another story, coming soon
.
September 10, 2009 at 4:23 pm |
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.
September 10, 2009 at 7:05 pm |
hi Sandra,
thank you for your visit and nice comment,
i guess you typed wrong your webpage “google.com/uzkbs”.
my regards.