On Friday 05 November 2004 15:17, Alistair A. Israel wrote:
> > public void testSetWidthBadValue() {
> > MyRectangle rect = new MyRectangle();
> >
> > try{
> > rect.setWidth(-5);
> > fail("negative widths are illegal");
> > }
> > catch(IllegalArgumentException expected)
> > {}
> > }
>
> My comments to this approach (and it seems everybody else does this,
> as seen by three nearly identical responses to the original post):
>
> 1. Empty {} block. I dunno, I'm anal that way.
I have a pass() method in my extending-TestCase-superclass for just
this reason.
> 2. It's easy to make the mistake of catching Exception - which will
> cause the test to pass if _any_ exception is thrown, even if it wasn't
> the one expected.
I don't find it easy - I know what exception I want to catch, and
writing the "wrong" one gives me the heebie-jeebies.
--
Chris "electric hedgehog" Dollin