Make sure tests are failing, not error-ing out

From: Manfred Riem <>
Date: Mon, 06 Feb 2012 09:36:00 -0600

Hi all,

For our integration and unit testing we really need to make sure that
our tests fail instead of error out.

What that means is that if you are expecting an Exception you assert
that the exception happens. It also means that if your test errors out
because some setups fails you will need to readjust the code so it
asserts a particular environment.


1. UIComponent found = component.getChildren().get(0);
2. assertNotNull(found);

The example above can error out because the number of
children could be 0, in which case this test would error
out at line 1 instead of fail at line 2.

There are more than one way to solve the above problem
but a way could be:

assertTrue(component.getChildren().size() > 0);
UIComponent found = component.getChildren().get(0);

Note we are guarding against the possibility here the
number of children is actually 0.

If you have any questions, don't hesitate to ask me.

Kind regards,