From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23118 invoked by alias); 3 Jul 2007 21:52:24 -0000 Received: (qmail 23108 invoked by uid 22791); 3 Jul 2007 21:52:23 -0000 X-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,DK_POLICY_SIGNSOME,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 03 Jul 2007 21:52:18 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.1/8.13.1) with ESMTP id l63LqGUt002131 for ; Tue, 3 Jul 2007 17:52:16 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l63LqGQV022820 for ; Tue, 3 Jul 2007 17:52:16 -0400 Received: from [127.0.0.1] (sebastian-int.corp.redhat.com [172.16.52.221]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l63LqFmD010920 for ; Tue, 3 Jul 2007 17:52:15 -0400 Message-ID: <468AC518.8050101@redhat.com> Date: Tue, 03 Jul 2007 21:52:00 -0000 From: Andrew Cagney User-Agent: Thunderbird 1.5.0.12 (X11/20070530) MIME-Version: 1.0 To: frysk Subject: test case, exceptions, and tearDown Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2007-q3/txt/msg00016.txt.bz2 Just FYI, Todays IRC had a bit of discussion regarding how a JUnit test is written (as a style thing). I've found the JUnit faq ( http://junit.sourceforge.net/doc/faq/faq.htm ), even though it is using version 4 code, makes for a good reference for how the authors intended the framework to be used. Two answers I found useful: > *How do I write a test that fails when an unexpected exception is > thrown?* > > Declare the exception in the |throws| clause of the test method and > don't catch the exception within the test method. Uncaught exceptions > will cause the test to fail with an error. > > The following is an example test that fails when the > |IndexOutOfBoundsException| is raised: > > | > > @Test > public void testIndexOutOfBoundsExceptionNotRaised() > throws IndexOutOfBoundsException { > > ArrayList emptyList = new ArrayList(); > Object o = emptyList.get(0); > } > | Notice how the exception doesn't need to be explicitly caught; instead the exception being thrown is interpreted as a FAIL. and: > *When are tests garbage collected?* > > /(Submitted by: Timothy Wall and Kent Beck)/ > > By design, the tree of Test instances is built in one pass, then the > tests are executed in a second pass. The test runner holds strong > references to all Test instances for the duration of the test > execution. This means that for a very long test run with many Test > instances, none of the tests may be garbage collected until the end of > the entire test run. > > Therefore, if you allocate external or limited resources in a test, > you are responsible for freeing those resources. Explicitly setting an > object to |null| in the |tearDown()| method, for example, allows it to > be garbage collected before the end of the entire test run. > Things involving file-descriptors would certainly fall into that category. Something to keep an eye out for :-) Andrew