jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Massol" <vmas...@pivolis.com>
Subject RE: Test sequence
Date Thu, 15 Apr 2004 09:24:35 GMT
Hi Colum,

> -----Original Message-----
> From: Colum O'Dea [mailto:codea@europe.yahoo-inc.com]
> Sent: 14 April 2004 17:12
> To: cactus-user@jakarta.apache.org
> Subject: Test sequence
> 
> Hi all,
> I'm new to cactus and have just created a test class to test some
> registration scenarios in a project I'm involved in.
> It seems that the test methods are not run in any particular sequence,
is
> this true?

It depends. If you don't create your test suite manually, JUnit creates
one for you, picking up all methods starting with "test". If you wish to
order them, you need to create a manual test suite. For example:

public static Test suite()
{
  TestSuite suite = new TestSuite();
  suite.addTest(new MyTest("testMytest1"));
  suite.addTest(new MyTest("testMytest2"));
  [...]
  return suite;
}

Be warned though that trying to order tests is usually symptomatic of an
issue. Normally you're not supposed to order unit tests. They can share
a fixture (which is put in begin() or setUp() methods) but a *unit* test
is not supposed to depend on another one. It makes the test suite more
brittle. See the JUnit FAQ for more on this subject.

Thanks
-Vincent

> 
> My class has two test methods and I would like the tests to be run in
a
> particular sequence. I don't want the tests to call each other in a
begin
> method as this would mean that some tests will be called a lot of
times.
> 
> Any help in setting a specific order would be greatly appreciated.
> Colum.
> 

[snip]


> 
> My test class is as follows :
> 
> /*
>  * Copyright (c) 2004 Yahoo! Inc
>  * All rights reserved.
>  *
>  */
> package com.yahoo.gmmh.test.user;
> 
> import org.apache.cactus.ServletTestCase;
> import junit.framework.Test;
> import junit.framework.TestSuite;
> import com.yahoo.gmmh.ejb.user.interfaces.RegistrationManager;
> import com.yahoo.gmmh.ejb.user.interfaces.RegistrationManagerUtil;
> import org.apache.log4j.Category;
> import com.yahoo.gmmh.hibernate.UserProfile;
> import com.yahoo.gmmh.test.GMMHTestSuite;
> import com.yahoo.gmmh.hibernate.MobileDevice;
> 
> /**
>  */
> public class RegistrationManagerTest extends ServletTestCase {
>   /**
>    * Static reference to Log4J Logger.
>    */
>   private static final Category LOG =
> Category.getInstance(RegistrationManagerTest.class);
> 
>   /**
>    * The session bean which is being tested.
>    */
>   private RegistrationManager regMgr =
> RegistrationManagerUtil.getHome().create();
> 
>   /**
>    * Default constructor
>    *
>    * @param testCaseName The name of the test case.
>    */
>   public RegistrationManagerTest(String testCaseName)
>   {
>     super(testCaseName);
>   }
> 
>   /**
>    * Tests creating a completely new user with only a yid.
>    *
>    * @throws Exception If unable to execute the test case.
>    */
>   public void testCreateNewUserProfile() throws Exception
>   {
>     if(LOG.isDebugEnabled()) {
>       LOG.debug("Running test 'testCreateNewUserProfile'");
>     }
> 
>     UserProfile userProfile =
> this.regMgr.createNewUserProfile(GMMHTestSuite.testUser);
> 
>     // check to ensure the yid is correct.
>     assertEquals(GMMHTestSuite.testUser, userProfile.getYahooID());
>   }
> 
>   /**
>    * Tests adding an msisdn to an existing user.
>    *
>    * @throws Exception If unable to execute the test case.
>    */
>   public void testAddMobileDeviceToUser() throws Exception
>   {
>     if(LOG.isDebugEnabled()) {
>       LOG.debug("Running test 'testAddMobileDeviceToUser'");
>     }
> 
>     UserProfile userProfile =
> this.regMgr.addMobileDeviceToUser(GMMHTestSuite.testUser,
> 
> GMMHTestSuite.testMSISDN);
> 
>     // check to ensure the yid is correct.
>     assertEquals(GMMHTestSuite.testUser, userProfile.getYahooID());
>   }
> 
> 
>   /**
>    * Start the tests.
>    *
>    * @param theArgs String[]
>    */
>   public static void main (String[] theArgs) {
>     junit.swingui.TestRunner.main(new String[]
> {RegistrationManagerTest.class.getName()});
>   }
> 
>   /**
>    * Creates the testsuite of all the tests to be run. <br/>
>    *
>    * @return a test suite that includes all methods starting with
"test"
>    */
>   public static Test suite () {
>     return new TestSuite(RegistrationManagerTest.class);
>   }
> }
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _____________________________________________________________
> 
>    Colum O'Dea  codea@europe.yahoo-inc.com
>    Mobile Engineer, Yahoo! Europe
>    Yahoo! Europe, 10 Ebury Bridge Road, London, SW1 W8PZ, GB
>    Tel   :  +44 20 7808 4498   Fax     : +44 20 7808 4414
>    Mob   :  +44 79 7326 0043   YahooID : columod
> 
>    "If at first you do succeed try not to look astonished!!"
> _____________________________________________________________
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org



Mime
View raw message