Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 82439 invoked from network); 1 Oct 2010 14:34:40 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Oct 2010 14:34:40 -0000 Received: (qmail 69720 invoked by uid 500); 1 Oct 2010 14:34:40 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 69526 invoked by uid 500); 1 Oct 2010 14:34:38 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 69517 invoked by uid 99); 1 Oct 2010 14:34:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Oct 2010 14:34:38 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [193.74.71.27] (HELO eir.is.scarlet.be) (193.74.71.27) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Oct 2010 14:34:29 +0000 Received: from mail.harfang.homelinux.org (ip-62-235-227-114.dsl.scarlet.be [62.235.227.114]) by eir.is.scarlet.be (8.14.2/8.14.2) with ESMTP id o91EY8kD004737 for ; Fri, 1 Oct 2010 16:34:08 +0200 Received: from localhost (mail.harfang.homelinux.org [192.168.20.11]) by mail.harfang.homelinux.org (Postfix) with ESMTP id 4BFC461803 for ; Fri, 1 Oct 2010 16:34:08 +0200 (CEST) Received: from mail.harfang.homelinux.org ([192.168.20.11]) by localhost (mail.harfang.homelinux.org [192.168.20.11]) (amavisd-new, port 10024) with ESMTP id c6BSl+2ukzQr for ; Fri, 1 Oct 2010 16:34:06 +0200 (CEST) Received: from dusk.harfang.homelinux.org (mail.harfang.homelinux.org [192.168.20.11]) by mail.harfang.homelinux.org (Postfix) with ESMTP id 46817617BA for ; Fri, 1 Oct 2010 16:34:06 +0200 (CEST) Received: from eran by dusk.harfang.homelinux.org with local (Exim 4.71) (envelope-from ) id 1P1ggY-0005gP-1X for dev@commons.apache.org; Fri, 01 Oct 2010 16:34:06 +0200 Date: Fri, 1 Oct 2010 16:34:05 +0200 From: Gilles Sadowski To: dev@commons.apache.org Subject: Re: [MATH] Change test code to remove fail("wrong exception type caught") Message-ID: <20101001143405.GH12035@dusk.harfang.homelinux.org> Mail-Followup-To: dev@commons.apache.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Tiny Tux X-PGP-Key-Fingerprint: 53B9 972E C2E6 B93C BEAD 7092 09E6 AF46 51D0 5641 User-Agent: Mutt/1.5.20 (2009-06-14) X-DCC-scarlet.be-Metrics: eir 20002; Body=1 Fuz1=1 Fuz2=1 X-Virus-Checked: Checked by ClamAV on apache.org 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.] Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org