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 ;) .

Leave a Reply