On 1 October 2010 15:34, Gilles Sadowski <gil...@harfang.homelinux.org> wrote:
> On Fri, Oct 01, 2010 at 03:17:58PM +0100, sebb wrote:
>> There are quite a few test cases that have code like:
>>
>> public void testSomething(){
>>     try {
>>       something();
>>       fail("an exception should have been caught");
>>     } catch (EstimationException ee) {
>>       // expected behavior
>>     } catch (Exception e) {
>>       fail("wrong exception type caught");
>>     }
>> }
>>
>> This is unnecessary code; worse, the actual Exception is lost.
>>
>> I propose to fix these by converting them to:
>>
>> public void testSomething() throws Exception {
>>     try {
>>       something();
>>       fail("Expecting EstimationException ");
>>     } catch (EstimationException ee) {
>>       // expected behavior
>> }
>>
>> Any objections?
>
> Shouldn't we move to JUnit 4, i.e. using
> ---CUT---
>   �...@test(expected=EstimationException.class)
>    public void testSomething() {
>        something();
>    }
> ---CUT---
>
> [Of course, this would force to split the test methods that currently
> contain multiple statements that can throw an exception.]

Yes, I wondered about that. But it's more work.

Removing the catch(Exception) is fairly mechanical (and would have to
be done anyway when moving to JUnit 4, so would not be wasted).

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to