Return-Path: Delivered-To: apmail-directory-dev-archive@www.apache.org Received: (qmail 69984 invoked from network); 16 Mar 2005 17:47:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 16 Mar 2005 17:47:35 -0000 Received: (qmail 80886 invoked by uid 500); 16 Mar 2005 17:47:34 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 80783 invoked by uid 500); 16 Mar 2005 17:47:33 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 80758 invoked by uid 500); 16 Mar 2005 17:47:33 -0000 Delivered-To: apmail-incubator-directory-dev@incubator.apache.org Received: (qmail 80748 invoked by uid 99); 16 Mar 2005 17:47:33 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from ensim1.25oz.com (HELO ensim1.25oz.com) (216.40.203.202) by apache.org (qpsmtpd/0.28) with ESMTP; Wed, 16 Mar 2005 09:47:32 -0800 Received: from [192.168.1.129] ([66.208.37.51]) (authenticated bits=0) by ensim1.25oz.com (8.12.10/8.12.10) with ESMTP id j2GJ7Ffk002966; Wed, 16 Mar 2005 14:07:16 -0500 Message-ID: <42387130.9030403@d-haven.org> Date: Wed, 16 Mar 2005 12:47:28 -0500 From: Berin Loritsch User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Apache Directory Developers List CC: "'Apache Directory Developers List'" Subject: Re: Tests naming References: <777DDD941E46D41181B300508BAE014F0DDD41AA@synntm8.mtl.optimumgroup.com> In-Reply-To: <777DDD941E46D41181B300508BAE014F0DDD41AA@synntm8.mtl.optimumgroup.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Tenc�, Vincent wrote: >I started looking at removing Snacc dep in asn1/ber and came accross this >test I have to change. But I have no clue what it is doing: > > public void testAbandonMessage() throws Exception > { > AbandonRequestImpl request = new AbandonRequestImpl( 1 ) ; > request.setAbandoned( 3 ) ; > decode( request ) ; > roundTripTest( request ) ; > assertFalse( tlvList.isEmpty() ) ; > } > >I'll take the opportunity to discuss test methods naming. The issue with >this sort of naming is that it doesn't help if you don't know the code - I >hope it's clear at least to someone who knows the code ;-) - so you lose a >the power of test as a documentation mechanism. Basically I'm stuck, not >knowing what the code does nor what the test is trying to prove. > >The approach I favor is to name test methods so that they describe the >intention of the test, rather than the method or the data under test. For >example, if I'm writing a test for a decorator that caches compiled java >classes from script, instead of writing tests like: > >testLoadClass() >testLoadClassTwice() > >I would favor: > >testClassesAreRetrievedFromCacheIfScriptHasNotChanged() >testClassesAreReloadedIfScriptWasChanged > >I have found that this practise helps a lot in documenting tests and code, >for others as well as yourself when you're reading your tests later on. It >also helps clarify what you're trying to achieve when you're writing the >test. It keeps you focused and helps think of other test cases you're not >covering. > >I'd like to hear what you guys have to say on this, and discuss the adoption >of such a practise for the project. When we're at it, I'd like to open a >discussion on the testing practices we want to enforce. > >Cheers, >-- Vincent > > > I agree to a certain extent, although tracability back to the method we are testing is helpful to me. I tend to favor a variation on what you do. I use the method name followed by descriptions. For a method named "loadClass" I would do something like this: testLoadClass() // normal critical path testLoadClass_fromCacheIfScriptNotChanged() testLoadClass_noClassNameProvided() testLoadClass_reloadIfScriptChanged() Each testing a different specific aspect of the method. I will have a different test for each permutation or branch I have to ensure works properly. If there are branches I can't excersize from the test harness then it is dead code and needs to be removed. The approach I use gives both the tracability to the method and the clarity you desire. Just my 2 cents.