Just stop catching AssertionError
exceptions and you will see your tests failing as expected.
Why this so? When an assertion evaluates to false:
assertEquals(3, 5);
assertThat(3, is(equalTo(5)));
assert 3 == 5;
in all those cases it throws AssertionError
exception. Any exception thrown in the test terminates the test, unless it is caught. So in your case, if you catch the exception, then your test is not terminated and considered as passed. A test execution framework (TestNG, JUnit, etc.) has simply no knowledge that any assertion failed.
However, if your test throws an exception, whether it is AssertionError
or other exception, the test execution framework will consider your test as failed (with one small exception to SkipException
that the test execution framework will mark your test as skipped).
You haven't explained why you catch AssertionError
in your test. But if you care about printing the stacktrace of AssertionError
, your test execution framework will do it for you automatically after failing the test. So printing it explicitly in your test is not necessary.
catch(AssertionError){}
.