jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Honghai Zhang" <honghai.zh...@towers.com>
Subject RE: Test EJBs
Date Wed, 23 Oct 2002 17:52:50 GMT


Vincent,

Thanks for the suggestion. I got your point.

Regards,

Honghai Zhang
TPAS, Towers Perrin


                                                                                         
                                             
                                                                                         
                                             
                                               To:       "'Cactus Users List'" <cactus-user@jakarta.apache.org>
                       
                      "Vincent Massol"         cc:       (bcc: Honghai Zhang/Towers Perrin)
                                           
                      <vmassol@octo.com        Subject:  RE: Test EJBs                
                                                
                      >                                                               
                                                
                                                                                         
                                             
                      10/23/2002 11:14                                                   
                                             
                      AM                                                                 
                                             
                      Please respond to                                                  
                                             
                      "Cactus Users                                                      
                                             
                      List"                                                              
                                             
                                                                                         
                                             
                                                                                         
                                             




Hi Honghai,

Just a comment. Mark is correct but this is not the way to do it if
you're performing unit tests. A unit test *must* be independent from
another one. For each test, you must supply whatever initialization is
needed.

This is not a valid unit test:

     public void testMinus() throws Exception {
        int diff = ejb2.minus(sum, 3);
        assertEquals(2, diff);
    }

A valid one is :

     public void testMinus1() throws Exception {
        int diff = ejb2.minus(5, 3);
        assertEquals(2, diff);
    }

     public void testMinus2() throws Exception {
        int diff = ejb2.minus(2, 3);
        assertEquals(-1, diff);
    }

for example.

Hope it helps,
-Vincent

> -----Original Message-----
> From: Honghai Zhang [mailto:honghai.zhang@towers.com]
> Sent: 23 October 2002 15:55
> To: Cactus Users List
> Cc: mwehby@TRIPLEI.COM
> Subject: Re: Test EJBs
>
>
>
>
> It worked. Thanks Mark,
>
>
>
> Honghai
>
>
>
>
>                                                To:       "Cactus Users
> List" <cactus-user@jakarta.apache.org>
>                       "Mark Wehby"             cc:       (bcc: Honghai
> Zhang/Towers Perrin)
>                       <mwehby@TRIPLEI.C        Subject:  Re: Test EJBs
>                       OM>
>
>                       10/22/2002 03:02
>                       PM
>                       Please respond to
>                       "Cactus Users
>                       List"
>
>
>
>
>
>
>  In order to use this value in the second method, create a static
instance
> varible and place the value in it.  The way in which Cactus works, the
> CactusTest class is destroyed each time control is returned to the
> client-side.  In order to keep the sum variable value, you would need
to
> do
> the following.
>
>
>
>
>
////////////////////////////////////////////////////////////////////////
//
> //
>
> ////////////////////////////////////
>  public class CactusTest extends ServletTestCase {
>        private static int sum = 0;
>
>      public void testPlus() throws Exception {
>          sum = ejb.plus(2, 3);
>          assertEquals(5, sum);
>      }
>
>      public void testMinus() throws Exception {
>          int diff = ejb2.minus(sum, 3);
>          assertEquals(2, diff);
>      }
>
>  }
>
>
>
> ----- Original Message -----
> From: "Honghai Zhang" <honghai.zhang@towers.com>
> To: <cactus-user@jakarta.apache.org>
> Sent: Tuesday, October 22, 2002 2:35 PM
> Subject: Test EJBs
>
>
> >
> > I am using "ServletTestCase" to test EJBs deployed on Weblogic
Server
> 6.1.
> >
> > Here is the test scenario:
> > I have 2 EJBs I need to test.  I want to test one method for each
EJB.
> > The method of 2nd EJB uses the return value of the method of 1st
EJB.
> >
> > Here is the code
> >
> >
> >
> >
>
////////////////////////////////////////////////////////////////////////
//
> //
>
> ////////////////////////////////////
> > public class CactusTest extends ServletTestCase {
> > ...
> >     public void testPlus() throws Exception {
> >         sum = ejb.plus(2, 3);
> >         assertEquals(5, sum);
> >     }
> >
> >     public void testMinus() throws Exception {
> >         int diff = ejb2.minus(sum, 3);
> >         assertEquals(2, diff);
> >     }
> >
> > ....
> > }
> >
>
////////////////////////////////////////////////////////////////////////
//
> //
>
> ////////////////////////////////////////
> >
> >
> > It is does not work because I think the instance variable "sum" was
> > initialized to 0 when the method "testMinus()" was executed.  Does
> anyone
> > know why this happens? (May be 2nd instance was created?)
> >
> > What are the alternatives if this does not work?
> >
> > Regards,
> >
> > Honghai Zhang
> > TPAS, Towers Perrin
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:cactus-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> <mailto:cactus-user-help@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:   <
> mailto:cactus-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <
> mailto:cactus-user-help@jakarta.apache.org>
>
>
>
>
>
>
>
> --
> To unsubscribe, e-mail:   <mailto:cactus-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <
mailto:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <
mailto:cactus-user-help@jakarta.apache.org>







--
To unsubscribe, e-mail:   <mailto:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@jakarta.apache.org>


Mime
View raw message