> > However, I suggest not calling the tag assertFails, since (in > general) no > test failure is involved. How about <assertThrown> since > we are asserting > that an exception is being thrown. I particularly like the > idea of having > the expected Throwable (not just Exception) declared as an attribute. > > More concretely: > > <test:assertThrown expectedThrowable="MyException"> > <!-- do something --> > </test:assertThrown> >
Good suggestions. I have sent a patch to the dev list now which includes the <test:assertThrown/> tag as you describe it. I was thinking if not maybe the name should be <test:assertThrows/> instead? > This would catch the expectedThrowable. Any other throwable > would cause a > test failure (noting the thrown type). If no exception is > thrown when in > the body, the test fails too (noting that the expected > exception didn't > arrive). This way you avoid having to add a nested > <test:fail> tag all the > time. > Yes, that's the general idea. So the tag thrown an exception if its body doesn't throw one of the expected kind. Not that if you for example specify expectedThowable="java.io.IOException", it will also catch any exceptions derived from that class, like java.io.FileNotFoundException. And if no expectedThrowable is declared, all exceptions are caught. Also if the expectedThrowable attribute value doesn't denote an exception class or any class at all, then a warning is logged and any exception (java.lang.Throwable) is caught. Also I added the "var" attribute, as James suggested. -- knut
