Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 87630 invoked from network); 1 Oct 2010 14:49:24 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Oct 2010 14:49:24 -0000 Received: (qmail 90897 invoked by uid 500); 1 Oct 2010 14:49:23 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 90411 invoked by uid 500); 1 Oct 2010 14:49:21 -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 90403 invoked by uid 99); 1 Oct 2010 14:49:20 -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:49:20 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sebbaz@gmail.com designates 209.85.216.171 as permitted sender) Received: from [209.85.216.171] (HELO mail-qy0-f171.google.com) (209.85.216.171) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Oct 2010 14:49:13 +0000 Received: by qyk1 with SMTP id 1so3140067qyk.9 for ; Fri, 01 Oct 2010 07:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=z7jpWzKfKHCbSJ8yHqCosg2t/tBAZqpyBt8f7RsCkho=; b=jYAAmI6Tnkdch9yq7FKtdHcOUwxLjygbeBrER162XuLHLhh43me+LRy2mK0/FDriQk Ls9EFPvNV/vZTco/sYD/gBh8HBl+yWnuebzQGkQoAIzJTBLfRthISQArNgi9HUVTxMCV rARKw3fZa50Jh7xNoN6KuMmZ5IMOKz2AiDZ8E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=uq2Oq0ioNJWYVEac7zuJsEWv8/5XyMHlAqbXbtn8Frz3XfQl+5p0MN/a4zZ7xMoOjJ 5a7wC2U5Vs2GmIaA/ww0YAzSSEPkn6FvNshCFqTdUcJZZYaH7Vz1Xvt9jRMDxUdAE1Yc olTr/gd6xAUNWOuuReIXGZcDPHa7CVGjDODN0= MIME-Version: 1.0 Received: by 10.224.11.20 with SMTP id r20mr3827386qar.223.1285944513608; Fri, 01 Oct 2010 07:48:33 -0700 (PDT) Received: by 10.229.230.213 with HTTP; Fri, 1 Oct 2010 07:48:33 -0700 (PDT) In-Reply-To: <20101001143405.GH12035@dusk.harfang.homelinux.org> References: <20101001143405.GH12035@dusk.harfang.homelinux.org> Date: Fri, 1 Oct 2010 15:48:33 +0100 Message-ID: Subject: Re: [MATH] Change test code to remove fail("wrong exception type caught") From: sebb To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On 1 October 2010 15:34, Gilles Sadowski wro= te: > 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(){ >> =A0 =A0 try { >> =A0 =A0 =A0 something(); >> =A0 =A0 =A0 fail("an exception should have been caught"); >> =A0 =A0 } catch (EstimationException ee) { >> =A0 =A0 =A0 // expected behavior >> =A0 =A0 } catch (Exception e) { >> =A0 =A0 =A0 fail("wrong exception type caught"); >> =A0 =A0 } >> } >> >> This is unnecessary code; worse, the actual Exception is lost. >> >> I propose to fix these by converting them to: >> >> public void testSomething() throws Exception { >> =A0 =A0 try { >> =A0 =A0 =A0 something(); >> =A0 =A0 =A0 fail("Expecting EstimationException "); >> =A0 =A0 } catch (EstimationException ee) { >> =A0 =A0 =A0 // expected behavior >> } >> >> Any objections? > > Shouldn't we move to JUnit 4, i.e. using > ---CUT--- > =A0 =A0@Test(expected=3DEstimationException.class) > =A0 =A0public void testSomething() { > =A0 =A0 =A0 =A0something(); > =A0 =A0} > ---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-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org