BeforeSuite|Test|Class

View: New views
10 Messages — Rating Filter:   Alert me  

BeforeSuite|Test|Class

by threecuptea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

My project is written in EJB3.  In  order to test EJB, I have a parentClass
public abstract class EJBIntegrationTest with two BeforeSuites method
@BeforeSuite(alwaysRun = true)
    @Parameters({"deploy_beans_xml", "scan_classpath","jndi_name_emf", "jndi_name_usertx"})
    public void startContainer(String deployBeansXml, String scanClasspath,
                               String jndiNameEMF, String jndiNameUserTx)
            throws Exception {
     
        EJB3StandaloneBootstrap.boot(null);
        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
        EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/", File.separator));
    }
//Initialize environment for all subclass.
@BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
    public void initialEnvironment() throws Exception {      
        jndi = new InitialContext();
        programSession = lookupLocalBean(RemoteProgramSession.class, "ProgramSessionEJB");
        metaSession = lookupLocalBean(LocalMetadataSession.class,  "MetadataSessionEJB");
        authoringSession = lookupLocalBean(LocalAuthoringSession.class, "AuthoringSessionEJB");
        dashboardSession = lookupLocalBean(LocalDashboardSession.class, "DashboardSessionEJB");    
       EntityManager em = getEntityManagerFactory().createEntityManager();
        session  = (Session) em.getDelegate();
    }

All EJB test classes extends EJBIntegrationTest with a BeforeClass method to prepare default testing variables like the followings:
@Test(groups = "persistence-pandads-prgmgrp")
public class ProgramSessionTest extends EJBIntegrationTest {

@BeforeClass(groups="persistence-pandads-prgmgrp")
    public void prepareSettings() {
        dfltNetwork = programSession.getNetworkById(1);
        dfltContentRating = programSession.getContentRatingById(5);
        dfltProductType = programSession.getProductTypeById(2);
:
:}


It works fine until I add a second EJB test class MetadataSessionTest.   I found out prepareSettings method would always throws NullPointerException for whichever test class run second (test run in random order) because it is not able to access those EJBSession beans initialized in BeforeSuite method initialEnvironment.  prepareSettings method works fine for
whichever test class run first.  

I tried many ways.  Finally, I get it work by changing initialEnvironment. to BeforeTest method.  (Test includes all test classes).  initialEnvironment seems to run once for each test class (It's not my original intent)

I like to know
1) Why is the second test class unable to access variables initialized in before test suite method? I like to know the difference of implementation of BeforeSuite, BeforeTest, BeforeClass and how would that affect the running sequence and accessibility.
2) What should we put in beforeSuite, beforeTest, beforeClass in principle? What's your suggestion regarding to my case?

Re: BeforeSuite|Test|Class

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

A few thoughts.
  • Are you sure you want @BeforeTest and not @BeforeMethod?  The latter is much more common in my experience.

  • Can you simplify your code with just a few logs for each method called and post the log here?  This way we will see what methods are being invoked and in what order (you can also set verbose="10" in testng.xml and you'll get this information as well.

--
Cedric


On Sat, Oct 24, 2009 at 10:36 PM, threecuptea <sonya_ling1947@...> wrote:


My project is written in EJB3.  In  order to test EJB, I have a parentClass
public abstract class EJBIntegrationTest with two BeforeSuites method
@BeforeSuite(alwaysRun = true)
   @Parameters({"deploy_beans_xml", "scan_classpath","jndi_name_emf",
"jndi_name_usertx"})
   public void startContainer(String deployBeansXml, String scanClasspath,
                              String jndiNameEMF, String jndiNameUserTx)
           throws Exception {

       EJB3StandaloneBootstrap.boot(null);
       EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
       EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
File.separator));
   }
//Initialize environment for all subclass.
@BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
   public void initialEnvironment() throws Exception {
       jndi = new InitialContext();
       programSession = lookupLocalBean(RemoteProgramSession.class,
"ProgramSessionEJB");
       metaSession = lookupLocalBean(LocalMetadataSession.class,
"MetadataSessionEJB");
       authoringSession = lookupLocalBean(LocalAuthoringSession.class,
"AuthoringSessionEJB");
       dashboardSession = lookupLocalBean(LocalDashboardSession.class,
"DashboardSessionEJB");
      EntityManager em = getEntityManagerFactory().createEntityManager();
       session  = (Session) em.getDelegate();
   }

All EJB test classes extends EJBIntegrationTest with a BeforeClass method to
prepare default testing variables like the followings:
@Test(groups = "persistence-pandads-prgmgrp")
public class ProgramSessionTest extends EJBIntegrationTest {

@BeforeClass(groups="persistence-pandads-prgmgrp")
   public void prepareSettings() {
       dfltNetwork = programSession.getNetworkById(1);
       dfltContentRating = programSession.getContentRatingById(5);
       dfltProductType = programSession.getProductTypeById(2);
:
:}

It works fine until I add a second EJB test class MetadataSessionTest.   I
found out prepareSettings method would always throws NullPointerException
for whichever test class run second (test run in random order) because it is
not able to access those EJBSession beans initialized in BeforeSuite method
initialEnvironment.  prepareSettings method works fine for
whichever test class run first.

I tried many ways.  Finally, I get it work by changing initialEnvironment.
to BeforeTest method.  (Test includes all test classes).  initialEnvironment
seems to run once for each test class (It's not my original intent)

I like to know
1) Why is the second test class unable to access variables initialized in
before test suite method? I like to know the difference of implementation of
BeforeSuite, BeforeTest, BeforeClass and how would that affect the running
sequence and accessibility.
2) What should we put in beforeSuite, beforeTest, beforeClass in principle?
What's your suggestion regarding to my case?

--
View this message in context: http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26045430.html
Sent from the testng-users mailing list archive at Nabble.com.






--
Cédric



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: BeforeSuite|Test|Class

by threecuptea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

BeforeSuite.logBeforeTest.log
Hi Cedric:
I include the BeforeTest.log when I code initialEnvironment with that annotation.  In that case, all tests passed and  
BeforeSuite.log when I code initialEnvironment with that annotation.  In that case, prepareSettings in ProgramSessionTest class throws NullpointerException when access programSession and some tests failed or skipped.
initialEnvironment tries to new InitialContext and lookup sessionBean and EntityManagerFactory to be shared by child classes.
Also include excerpt of classes

public abstract class EJBIntegrationTest {
   @BeforeSuite(alwaysRun = true)
    public void startContainer() {
         EJB3StandaloneBootstrap.boot(null);
        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
        EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/", File.separator));
    }
   
   @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
    public void initialEnvironment() {
         jndi = new InitialContext();
        programSession = lookupLocalBean(RemoteProgramSession.class, "ProgramSessionEJB");
          :
    }
    OR
   @BeforeTest(alwaysRun = true)
    public void initialEnvironment() {
        jndi = new InitialContext();
        programSession = lookupLocalBean(RemoteProgramSession.class, "ProgramSessionEJB");
    }
}

@Test(groups = "persistence-pandads-prgmgrp")
public class ProgramSessionTest extends EJBIntegrationTest {
 @BeforeClass(groups={"persistence-pandads-prgmgrp"})
    public void prepareSettings() throws Exception {
        //line 59, NullPointerException if I use @TestSuite for initialEnvironment method
        dfltNetwork = programSession.getNetworkById(1);
  }
}

@Test(groups = "persistence-pandads-metadata")
public class MetadataSessionTest extends EJBIntegrationTest {
 @BeforeClass(groups={"persistence-pandads-metadata"})
    public void prepareSettings() throws Exception {
        dfltProductType = programSession.getProductTypeById(2);
    }
}
 <test name="Test1">
        <classes>
           <class name="com.ceg.panda.test.core.ejb.ProgramSessionTest"/>
           <class name="com.ceg.panda.test.core.ejb.MetadataSessionTest"/>
        </classes>  
    </test>

Cédric Beust ♔ wrote:
A few thoughts.

   - Are you sure you want @BeforeTest and not @BeforeMethod?  The latter is
   much more common in my experience.

   - Can you simplify your code with just a few logs for each method called
   and post the log here?  This way we will see what methods are being invoked
   and in what order (you can also set verbose="10" in testng.xml and you'll
   get this information as well.


--
Cedric


On Sat, Oct 24, 2009 at 10:36 PM, threecuptea <sonya_ling1947@yahoo.com>wrote:

>
>
> My project is written in EJB3.  In  order to test EJB, I have a parentClass
> public abstract class EJBIntegrationTest with two BeforeSuites method
> @BeforeSuite(alwaysRun = true)
>    @Parameters({"deploy_beans_xml", "scan_classpath","jndi_name_emf",
> "jndi_name_usertx"})
>    public void startContainer(String deployBeansXml, String scanClasspath,
>                               String jndiNameEMF, String jndiNameUserTx)
>            throws Exception {
>
>        EJB3StandaloneBootstrap.boot(null);
>        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
>        EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
> File.separator));
>    }
> //Initialize environment for all subclass.
> @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
>    public void initialEnvironment() throws Exception {
>        jndi = new InitialContext();
>        programSession = lookupLocalBean(RemoteProgramSession.class,
> "ProgramSessionEJB");
>        metaSession = lookupLocalBean(LocalMetadataSession.class,
> "MetadataSessionEJB");
>        authoringSession = lookupLocalBean(LocalAuthoringSession.class,
> "AuthoringSessionEJB");
>        dashboardSession = lookupLocalBean(LocalDashboardSession.class,
> "DashboardSessionEJB");
>       EntityManager em = getEntityManagerFactory().createEntityManager();
>        session  = (Session) em.getDelegate();
>    }
>
> All EJB test classes extends EJBIntegrationTest with a BeforeClass method
> to
> prepare default testing variables like the followings:
> @Test(groups = "persistence-pandads-prgmgrp")
> public class ProgramSessionTest extends EJBIntegrationTest {
>
> @BeforeClass(groups="persistence-pandads-prgmgrp")
>    public void prepareSettings() {
>        dfltNetwork = programSession.getNetworkById(1);
>        dfltContentRating = programSession.getContentRatingById(5);
>        dfltProductType = programSession.getProductTypeById(2);
> :
> :}
>
> It works fine until I add a second EJB test class MetadataSessionTest.   I
> found out prepareSettings method would always throws NullPointerException
> for whichever test class run second (test run in random order) because it
> is
> not able to access those EJBSession beans initialized in BeforeSuite method
> initialEnvironment.  prepareSettings method works fine for
> whichever test class run first.
>
> I tried many ways.  Finally, I get it work by changing initialEnvironment.
> to BeforeTest method.  (Test includes all test classes).
>  initialEnvironment
> seems to run once for each test class (It's not my original intent)
>
> I like to know
> 1) Why is the second test class unable to access variables initialized in
> before test suite method? I like to know the difference of implementation
> of
> BeforeSuite, BeforeTest, BeforeClass and how would that affect the running
> sequence and accessibility.
> 2) What should we put in beforeSuite, beforeTest, beforeClass in principle?
> What's your suggestion regarding to my case?
>
> --
> View this message in context:
> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26045430.html
> Sent from the testng-users mailing list archive at Nabble.com.
>
>
> >
>


--
Cédric

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: BeforeSuite|Test|Class

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm sorry I don't understand what you are saying.

How about you
  • Post your code
  • Tell me what ordering of invocation you are seeing
  • Tell me what ordering you expected
?

--
Cédric




On Mon, Oct 26, 2009 at 11:21 AM, threecuptea <sonya_ling1947@...> wrote:


http://www.nabble.com/file/p26064775/BeforeSuite.log BeforeSuite.log
http://www.nabble.com/file/p26064775/BeforeTest.log BeforeTest.log
Hi Cedric:
I include the BeforeTest.log when I code initialEnvironment with that
annotation.  In that case, all tests passed and
BeforeSuite.log when I code initialEnvironment with that annotation.  In
that case, prepareSettings in ProgramSessionTest class throws
NullpointerException when access programSession and some tests failed or
skipped.
initialEnvironment tries to new InitialContext and lookup sessionBean and
EntityManagerFactory to be shared by child classes.
Also include excerpt of classes

public abstract class EJBIntegrationTest {
  @BeforeSuite(alwaysRun = true)
   public void startContainer() {
        EJB3StandaloneBootstrap.boot(null);
       EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
       EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
File.separator));
   }

  @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
   public void initialEnvironment() {
        jndi = new InitialContext();
       programSession = lookupLocalBean(RemoteProgramSession.class,
"ProgramSessionEJB");
         :
   }
   OR
  @BeforeTest(alwaysRun = true)
   public void initialEnvironment() {
       jndi = new InitialContext();
       programSession = lookupLocalBean(RemoteProgramSession.class,
"ProgramSessionEJB");
   }
}

@Test(groups = "persistence-pandads-prgmgrp")
public class ProgramSessionTest extends EJBIntegrationTest {
 @BeforeClass(groups={"persistence-pandads-prgmgrp"})
   public void prepareSettings() throws Exception {
       //line 59, NullPointerException if I use @TestSuite for
initialEnvironment method
       dfltNetwork = programSession.getNetworkById(1);
 }
}

@Test(groups = "persistence-pandads-metadata")
public class MetadataSessionTest extends EJBIntegrationTest {
 @BeforeClass(groups={"persistence-pandads-metadata"})
   public void prepareSettings() throws Exception {
       dfltProductType = programSession.getProductTypeById(2);
   }
}
 <test name="Test1">
       <classes>
          <class name="com.ceg.panda.test.core.ejb.ProgramSessionTest"/>
          <class name="com.ceg.panda.test.core.ejb.MetadataSessionTest"/>
       </classes>
   </test>


Cédric Beust ♔ wrote:
>
> A few thoughts.
>
>    - Are you sure you want @BeforeTest and not @BeforeMethod?  The latter
> is
>    much more common in my experience.
>
>    - Can you simplify your code with just a few logs for each method
> called
>    and post the log here?  This way we will see what methods are being
> invoked
>    and in what order (you can also set verbose="10" in testng.xml and
> you'll
>    get this information as well.
>
>
> --
> Cedric
>
>
> On Sat, Oct 24, 2009 at 10:36 PM, threecuptea
> <sonya_ling1947@...>wrote:
>
>>
>>
>> My project is written in EJB3.  In  order to test EJB, I have a
>> parentClass
>> public abstract class EJBIntegrationTest with two BeforeSuites method
>> @BeforeSuite(alwaysRun = true)
>>    @Parameters({"deploy_beans_xml", "scan_classpath","jndi_name_emf",
>> "jndi_name_usertx"})
>>    public void startContainer(String deployBeansXml, String
>> scanClasspath,
>>                               String jndiNameEMF, String jndiNameUserTx)
>>            throws Exception {
>>
>>        EJB3StandaloneBootstrap.boot(null);
>>        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
>>        EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
>> File.separator));
>>    }
>> //Initialize environment for all subclass.
>> @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
>>    public void initialEnvironment() throws Exception {
>>        jndi = new InitialContext();
>>        programSession = lookupLocalBean(RemoteProgramSession.class,
>> "ProgramSessionEJB");
>>        metaSession = lookupLocalBean(LocalMetadataSession.class,
>> "MetadataSessionEJB");
>>        authoringSession = lookupLocalBean(LocalAuthoringSession.class,
>> "AuthoringSessionEJB");
>>        dashboardSession = lookupLocalBean(LocalDashboardSession.class,
>> "DashboardSessionEJB");
>>       EntityManager em = getEntityManagerFactory().createEntityManager();
>>        session  = (Session) em.getDelegate();
>>    }
>>
>> All EJB test classes extends EJBIntegrationTest with a BeforeClass method
>> to
>> prepare default testing variables like the followings:
>> @Test(groups = "persistence-pandads-prgmgrp")
>> public class ProgramSessionTest extends EJBIntegrationTest {
>>
>> @BeforeClass(groups="persistence-pandads-prgmgrp")
>>    public void prepareSettings() {
>>        dfltNetwork = programSession.getNetworkById(1);
>>        dfltContentRating = programSession.getContentRatingById(5);
>>        dfltProductType = programSession.getProductTypeById(2);
>> :
>> :}
>>
>> It works fine until I add a second EJB test class MetadataSessionTest.
>> I
>> found out prepareSettings method would always throws NullPointerException
>> for whichever test class run second (test run in random order) because it
>> is
>> not able to access those EJBSession beans initialized in BeforeSuite
>> method
>> initialEnvironment.  prepareSettings method works fine for
>> whichever test class run first.
>>
>> I tried many ways.  Finally, I get it work by changing
>> initialEnvironment.
>> to BeforeTest method.  (Test includes all test classes).
>>  initialEnvironment
>> seems to run once for each test class (It's not my original intent)
>>
>> I like to know
>> 1) Why is the second test class unable to access variables initialized in
>> before test suite method? I like to know the difference of implementation
>> of
>> BeforeSuite, BeforeTest, BeforeClass and how would that affect the
>> running
>> sequence and accessibility.
>> 2) What should we put in beforeSuite, beforeTest, beforeClass in
>> principle?
>> What's your suggestion regarding to my case?
>>
>> --
>> View this message in context:
>> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26045430.html
>> Sent from the testng-users mailing list archive at Nabble.com.
>>
>>
>> >
>>
>
>
> --
> Cédric
>
> >
>
>

--
View this message in context: http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26064775.html
Sent from the testng-users mailing list archive at Nabble.com.







--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: BeforeSuite|Test|Class

by threecuptea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

EJBIntegrationTest.java
ProgramSessionTest.java
MetadataSessionTest.java
Here you go.
Expected all passed but got NullPointerException in prepareSetting of either ProgramSessionTest or MetadataSessionTest class depending upon which class run second.  See BeforeSuite.log in my previous email.

It works fine once I switch to use @BeforeTest annotation on initialEnvironment.  See BeforeTest.log in my previous email.

Cédric Beust ♔ wrote:
I'm sorry I don't understand what you are saying.

How about you

   - Post your code
   - Tell me what ordering of invocation you are seeing
   - Tell me what ordering you expected

?

--
Cédric




On Mon, Oct 26, 2009 at 11:21 AM, threecuptea <sonya_ling1947@yahoo.com>wrote:

>
>
> http://www.nabble.com/file/p26064775/BeforeSuite.log BeforeSuite.log
> http://www.nabble.com/file/p26064775/BeforeTest.log BeforeTest.log
> Hi Cedric:
> I include the BeforeTest.log when I code initialEnvironment with that
> annotation.  In that case, all tests passed and
> BeforeSuite.log when I code initialEnvironment with that annotation.  In
> that case, prepareSettings in ProgramSessionTest class throws
> NullpointerException when access programSession and some tests failed or
> skipped.
> initialEnvironment tries to new InitialContext and lookup sessionBean and
> EntityManagerFactory to be shared by child classes.
> Also include excerpt of classes
>
> public abstract class EJBIntegrationTest {
>   @BeforeSuite(alwaysRun = true)
>    public void startContainer() {
>          EJB3StandaloneBootstrap.boot(null);
>        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
>        EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
> File.separator));
>    }
>
>    @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
>     public void initialEnvironment() {
>          jndi = new InitialContext();
>        programSession = lookupLocalBean(RemoteProgramSession.class,
> "ProgramSessionEJB");
>           :
>    }
>    OR
>   @BeforeTest(alwaysRun = true)
>    public void initialEnvironment() {
>         jndi = new InitialContext();
>        programSession = lookupLocalBean(RemoteProgramSession.class,
> "ProgramSessionEJB");
>    }
> }
>
> @Test(groups = "persistence-pandads-prgmgrp")
> public class ProgramSessionTest extends EJBIntegrationTest {
>  @BeforeClass(groups={"persistence-pandads-prgmgrp"})
>     public void prepareSettings() throws Exception {
>        //line 59, NullPointerException if I use @TestSuite for
> initialEnvironment method
>        dfltNetwork = programSession.getNetworkById(1);
>  }
> }
>
> @Test(groups = "persistence-pandads-metadata")
> public class MetadataSessionTest extends EJBIntegrationTest {
>  @BeforeClass(groups={"persistence-pandads-metadata"})
>    public void prepareSettings() throws Exception {
>        dfltProductType = programSession.getProductTypeById(2);
>    }
> }
>  <test name="Test1">
>        <classes>
>           <class name="com.ceg.panda.test.core.ejb.ProgramSessionTest"/>
>           <class name="com.ceg.panda.test.core.ejb.MetadataSessionTest"/>
>        </classes>
>    </test>
>
>
> Cédric Beust ♔ wrote:
> >
> > A few thoughts.
> >
> >    - Are you sure you want @BeforeTest and not @BeforeMethod?  The latter
> > is
> >    much more common in my experience.
> >
> >    - Can you simplify your code with just a few logs for each method
> > called
> >    and post the log here?  This way we will see what methods are being
> > invoked
> >    and in what order (you can also set verbose="10" in testng.xml and
> > you'll
> >    get this information as well.
> >
> >
> > --
> > Cedric
> >
> >
> > On Sat, Oct 24, 2009 at 10:36 PM, threecuptea
> > <sonya_ling1947@yahoo.com>wrote:
> >
> >>
> >>
> >> My project is written in EJB3.  In  order to test EJB, I have a
> >> parentClass
> >> public abstract class EJBIntegrationTest with two BeforeSuites method
> >> @BeforeSuite(alwaysRun = true)
> >>    @Parameters({"deploy_beans_xml", "scan_classpath","jndi_name_emf",
> >> "jndi_name_usertx"})
> >>    public void startContainer(String deployBeansXml, String
> >> scanClasspath,
> >>                               String jndiNameEMF, String jndiNameUserTx)
> >>            throws Exception {
> >>
> >>        EJB3StandaloneBootstrap.boot(null);
> >>        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
> >>        EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
> >> File.separator));
> >>    }
> >> //Initialize environment for all subclass.
> >> @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
> >>    public void initialEnvironment() throws Exception {
> >>        jndi = new InitialContext();
> >>        programSession = lookupLocalBean(RemoteProgramSession.class,
> >> "ProgramSessionEJB");
> >>        metaSession = lookupLocalBean(LocalMetadataSession.class,
> >> "MetadataSessionEJB");
> >>        authoringSession = lookupLocalBean(LocalAuthoringSession.class,
> >> "AuthoringSessionEJB");
> >>        dashboardSession = lookupLocalBean(LocalDashboardSession.class,
> >> "DashboardSessionEJB");
> >>       EntityManager em =
> getEntityManagerFactory().createEntityManager();
> >>        session  = (Session) em.getDelegate();
> >>    }
> >>
> >> All EJB test classes extends EJBIntegrationTest with a BeforeClass
> method
> >> to
> >> prepare default testing variables like the followings:
> >> @Test(groups = "persistence-pandads-prgmgrp")
> >> public class ProgramSessionTest extends EJBIntegrationTest {
> >>
> >> @BeforeClass(groups="persistence-pandads-prgmgrp")
> >>    public void prepareSettings() {
> >>        dfltNetwork = programSession.getNetworkById(1);
> >>        dfltContentRating = programSession.getContentRatingById(5);
> >>        dfltProductType = programSession.getProductTypeById(2);
> >> :
> >> :}
> >>
> >> It works fine until I add a second EJB test class MetadataSessionTest.
> >> I
> >> found out prepareSettings method would always throws
> NullPointerException
> >> for whichever test class run second (test run in random order) because
> it
> >> is
> >> not able to access those EJBSession beans initialized in BeforeSuite
> >> method
> >> initialEnvironment.  prepareSettings method works fine for
> >> whichever test class run first.
> >>
> >> I tried many ways.  Finally, I get it work by changing
> >> initialEnvironment.
> >> to BeforeTest method.  (Test includes all test classes).
> >>  initialEnvironment
> >> seems to run once for each test class (It's not my original intent)
> >>
> >> I like to know
> >> 1) Why is the second test class unable to access variables initialized
> in
> >> before test suite method? I like to know the difference of
> implementation
> >> of
> >> BeforeSuite, BeforeTest, BeforeClass and how would that affect the
> >> running
> >> sequence and accessibility.
> >> 2) What should we put in beforeSuite, beforeTest, beforeClass in
> >> principle?
> >> What's your suggestion regarding to my case?
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26045430.html
> >> Sent from the testng-users mailing list archive at Nabble.com.
> >>
> >>
> >> >
> >>
> >
> >
> > --
> > Cédric
> >
> > >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26064775.html
> Sent from the testng-users mailing list archive at Nabble.com.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: BeforeSuite|Test|Class

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

So it looks like initialEnvironment() is never called with @BeforeSuite but does get called if you use @BeforeTest instead?

Please set <suite verbose="10"> and post the log.

--
Cédric



On Mon, Oct 26, 2009 at 12:38 PM, threecuptea <sonya_ling1947@...> wrote:


http://www.nabble.com/file/p26066107/EJBIntegrationTest.java
EJBIntegrationTest.java
http://www.nabble.com/file/p26066107/ProgramSessionTest.java
ProgramSessionTest.java
http://www.nabble.com/file/p26066107/MetadataSessionTest.java
MetadataSessionTest.java
Here you go.
Expected all passed but got NullPointerException in prepareSetting of either
ProgramSessionTest or MetadataSessionTest class depending upon which class
run second.  See BeforeSuite.log in my previous email.

It works fine once I switch to use @BeforeTest annotation on
initialEnvironment.  See BeforeTest.log in my previous email.


Cédric Beust ♔ wrote:
>
> I'm sorry I don't understand what you are saying.
>
> How about you
>
>    - Post your code
>    - Tell me what ordering of invocation you are seeing
>    - Tell me what ordering you expected
>
> ?
>
> --
> Cédric
>
>
>
>
> On Mon, Oct 26, 2009 at 11:21 AM, threecuptea
> <sonya_ling1947@...>wrote:
>
>>
>>
>> http://www.nabble.com/file/p26064775/BeforeSuite.log BeforeSuite.log
>> http://www.nabble.com/file/p26064775/BeforeTest.log BeforeTest.log
>> Hi Cedric:
>> I include the BeforeTest.log when I code initialEnvironment with that
>> annotation.  In that case, all tests passed and
>> BeforeSuite.log when I code initialEnvironment with that annotation.  In
>> that case, prepareSettings in ProgramSessionTest class throws
>> NullpointerException when access programSession and some tests failed or
>> skipped.
>> initialEnvironment tries to new InitialContext and lookup sessionBean and
>> EntityManagerFactory to be shared by child classes.
>> Also include excerpt of classes
>>
>> public abstract class EJBIntegrationTest {
>>   @BeforeSuite(alwaysRun = true)
>>    public void startContainer() {
>>          EJB3StandaloneBootstrap.boot(null);
>>        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
>>        EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
>> File.separator));
>>    }
>>
>>    @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
>>     public void initialEnvironment() {
>>          jndi = new InitialContext();
>>        programSession = lookupLocalBean(RemoteProgramSession.class,
>> "ProgramSessionEJB");
>>           :
>>    }
>>    OR
>>   @BeforeTest(alwaysRun = true)
>>    public void initialEnvironment() {
>>         jndi = new InitialContext();
>>        programSession = lookupLocalBean(RemoteProgramSession.class,
>> "ProgramSessionEJB");
>>    }
>> }
>>
>> @Test(groups = "persistence-pandads-prgmgrp")
>> public class ProgramSessionTest extends EJBIntegrationTest {
>>  @BeforeClass(groups={"persistence-pandads-prgmgrp"})
>>     public void prepareSettings() throws Exception {
>>        //line 59, NullPointerException if I use @TestSuite for
>> initialEnvironment method
>>        dfltNetwork = programSession.getNetworkById(1);
>>  }
>> }
>>
>> @Test(groups = "persistence-pandads-metadata")
>> public class MetadataSessionTest extends EJBIntegrationTest {
>>  @BeforeClass(groups={"persistence-pandads-metadata"})
>>    public void prepareSettings() throws Exception {
>>        dfltProductType = programSession.getProductTypeById(2);
>>    }
>> }
>>  <test name="Test1">
>>        <classes>
>>           <class name="com.ceg.panda.test.core.ejb.ProgramSessionTest"/>
>>           <class name="com.ceg.panda.test.core.ejb.MetadataSessionTest"/>
>>        </classes>
>>    </test>
>>
>>
>> Cédric Beust ♔ wrote:
>> >
>> > A few thoughts.
>> >
>> >    - Are you sure you want @BeforeTest and not @BeforeMethod?  The
>> latter
>> > is
>> >    much more common in my experience.
>> >
>> >    - Can you simplify your code with just a few logs for each method
>> > called
>> >    and post the log here?  This way we will see what methods are being
>> > invoked
>> >    and in what order (you can also set verbose="10" in testng.xml and
>> > you'll
>> >    get this information as well.
>> >
>> >
>> > --
>> > Cedric
>> >
>> >
>> > On Sat, Oct 24, 2009 at 10:36 PM, threecuptea
>> > <sonya_ling1947@...>wrote:
>> >
>> >>
>> >>
>> >> My project is written in EJB3.  In  order to test EJB, I have a
>> >> parentClass
>> >> public abstract class EJBIntegrationTest with two BeforeSuites method
>> >> @BeforeSuite(alwaysRun = true)
>> >>    @Parameters({"deploy_beans_xml", "scan_classpath","jndi_name_emf",
>> >> "jndi_name_usertx"})
>> >>    public void startContainer(String deployBeansXml, String
>> >> scanClasspath,
>> >>                               String jndiNameEMF, String
>> jndiNameUserTx)
>> >>            throws Exception {
>> >>
>> >>        EJB3StandaloneBootstrap.boot(null);
>> >>        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
>> >>
>> EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
>> >> File.separator));
>> >>    }
>> >> //Initialize environment for all subclass.
>> >> @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
>> >>    public void initialEnvironment() throws Exception {
>> >>        jndi = new InitialContext();
>> >>        programSession = lookupLocalBean(RemoteProgramSession.class,
>> >> "ProgramSessionEJB");
>> >>        metaSession = lookupLocalBean(LocalMetadataSession.class,
>> >> "MetadataSessionEJB");
>> >>        authoringSession = lookupLocalBean(LocalAuthoringSession.class,
>> >> "AuthoringSessionEJB");
>> >>        dashboardSession = lookupLocalBean(LocalDashboardSession.class,
>> >> "DashboardSessionEJB");
>> >>       EntityManager em =
>> getEntityManagerFactory().createEntityManager();
>> >>        session  = (Session) em.getDelegate();
>> >>    }
>> >>
>> >> All EJB test classes extends EJBIntegrationTest with a BeforeClass
>> method
>> >> to
>> >> prepare default testing variables like the followings:
>> >> @Test(groups = "persistence-pandads-prgmgrp")
>> >> public class ProgramSessionTest extends EJBIntegrationTest {
>> >>
>> >> @BeforeClass(groups="persistence-pandads-prgmgrp")
>> >>    public void prepareSettings() {
>> >>        dfltNetwork = programSession.getNetworkById(1);
>> >>        dfltContentRating = programSession.getContentRatingById(5);
>> >>        dfltProductType = programSession.getProductTypeById(2);
>> >> :
>> >> :}
>> >>
>> >> It works fine until I add a second EJB test class MetadataSessionTest.
>> >> I
>> >> found out prepareSettings method would always throws
>> NullPointerException
>> >> for whichever test class run second (test run in random order) because
>> it
>> >> is
>> >> not able to access those EJBSession beans initialized in BeforeSuite
>> >> method
>> >> initialEnvironment.  prepareSettings method works fine for
>> >> whichever test class run first.
>> >>
>> >> I tried many ways.  Finally, I get it work by changing
>> >> initialEnvironment.
>> >> to BeforeTest method.  (Test includes all test classes).
>> >>  initialEnvironment
>> >> seems to run once for each test class (It's not my original intent)
>> >>
>> >> I like to know
>> >> 1) Why is the second test class unable to access variables initialized
>> in
>> >> before test suite method? I like to know the difference of
>> implementation
>> >> of
>> >> BeforeSuite, BeforeTest, BeforeClass and how would that affect the
>> >> running
>> >> sequence and accessibility.
>> >> 2) What should we put in beforeSuite, beforeTest, beforeClass in
>> >> principle?
>> >> What's your suggestion regarding to my case?
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26045430.html
>> >> Sent from the testng-users mailing list archive at Nabble.com.
>> >>
>> >>
>> >> >
>> >>
>> >
>> >
>> > --
>> > Cédric
>> >
>> > >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26064775.html
>> Sent from the testng-users mailing list archive at Nabble.com.
>>
>>
>> >
>>
>
> >
>
>

--
View this message in context: http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26066107.html
Sent from the testng-users mailing list archive at Nabble.com.







--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: BeforeSuite|Test|Class

by threecuptea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I attached BeforeSuite.log & BeforeTest.log  with my message posted at 11:21 AM.  Let me know if you can access them.
Judging from BeforeSuite.log,
It did call once in initialEnvironment() with @BeforeSuite.

Cédric Beust ♔ wrote:
So it looks like initialEnvironment() is never called with @BeforeSuite but
does get called if you use @BeforeTest instead?

Please set <suite verbose="10"> and post the log.

--
Cédric



On Mon, Oct 26, 2009 at 12:38 PM, threecuptea <sonya_ling1947@yahoo.com>wrote:

>
>
> http://www.nabble.com/file/p26066107/EJBIntegrationTest.java
> EJBIntegrationTest.java
> http://www.nabble.com/file/p26066107/ProgramSessionTest.java
> ProgramSessionTest.java
> http://www.nabble.com/file/p26066107/MetadataSessionTest.java
> MetadataSessionTest.java
> Here you go.
> Expected all passed but got NullPointerException in prepareSetting of
> either
> ProgramSessionTest or MetadataSessionTest class depending upon which class
> run second.  See BeforeSuite.log in my previous email.
>
> It works fine once I switch to use @BeforeTest annotation on
> initialEnvironment.  See BeforeTest.log in my previous email.
>
>
> Cédric Beust ♔ wrote:
> >
> > I'm sorry I don't understand what you are saying.
> >
> > How about you
> >
> >    - Post your code
> >    - Tell me what ordering of invocation you are seeing
> >    - Tell me what ordering you expected
> >
> > ?
> >
> > --
> > Cédric
> >
> >
> >
> >
> > On Mon, Oct 26, 2009 at 11:21 AM, threecuptea
> > <sonya_ling1947@yahoo.com>wrote:
> >
> >>
> >>
> >> http://www.nabble.com/file/p26064775/BeforeSuite.log BeforeSuite.log
> >> http://www.nabble.com/file/p26064775/BeforeTest.log BeforeTest.log
> >> Hi Cedric:
> >> I include the BeforeTest.log when I code initialEnvironment with that
> >> annotation.  In that case, all tests passed and
> >> BeforeSuite.log when I code initialEnvironment with that annotation.  In
> >> that case, prepareSettings in ProgramSessionTest class throws
> >> NullpointerException when access programSession and some tests failed or
> >> skipped.
> >> initialEnvironment tries to new InitialContext and lookup sessionBean
> and
> >> EntityManagerFactory to be shared by child classes.
> >> Also include excerpt of classes
> >>
> >> public abstract class EJBIntegrationTest {
> >>   @BeforeSuite(alwaysRun = true)
> >>    public void startContainer() {
> >>          EJB3StandaloneBootstrap.boot(null);
> >>        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
> >>        EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
> >> File.separator));
> >>    }
> >>
> >>    @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
> >>     public void initialEnvironment() {
> >>          jndi = new InitialContext();
> >>        programSession = lookupLocalBean(RemoteProgramSession.class,
> >> "ProgramSessionEJB");
> >>           :
> >>    }
> >>    OR
> >>   @BeforeTest(alwaysRun = true)
> >>    public void initialEnvironment() {
> >>         jndi = new InitialContext();
> >>        programSession = lookupLocalBean(RemoteProgramSession.class,
> >> "ProgramSessionEJB");
> >>    }
> >> }
> >>
> >> @Test(groups = "persistence-pandads-prgmgrp")
> >> public class ProgramSessionTest extends EJBIntegrationTest {
> >>  @BeforeClass(groups={"persistence-pandads-prgmgrp"})
> >>     public void prepareSettings() throws Exception {
> >>        //line 59, NullPointerException if I use @TestSuite for
> >> initialEnvironment method
> >>        dfltNetwork = programSession.getNetworkById(1);
> >>  }
> >> }
> >>
> >> @Test(groups = "persistence-pandads-metadata")
> >> public class MetadataSessionTest extends EJBIntegrationTest {
> >>  @BeforeClass(groups={"persistence-pandads-metadata"})
> >>    public void prepareSettings() throws Exception {
> >>        dfltProductType = programSession.getProductTypeById(2);
> >>    }
> >> }
> >>  <test name="Test1">
> >>        <classes>
> >>           <class name="com.ceg.panda.test.core.ejb.ProgramSessionTest"/>
> >>           <class
> name="com.ceg.panda.test.core.ejb.MetadataSessionTest"/>
> >>        </classes>
> >>    </test>
> >>
> >>
> >> Cédric Beust ♔ wrote:
> >> >
> >> > A few thoughts.
> >> >
> >> >    - Are you sure you want @BeforeTest and not @BeforeMethod?  The
> >> latter
> >> > is
> >> >    much more common in my experience.
> >> >
> >> >    - Can you simplify your code with just a few logs for each method
> >> > called
> >> >    and post the log here?  This way we will see what methods are being
> >> > invoked
> >> >    and in what order (you can also set verbose="10" in testng.xml and
> >> > you'll
> >> >    get this information as well.
> >> >
> >> >
> >> > --
> >> > Cedric
> >> >
> >> >
> >> > On Sat, Oct 24, 2009 at 10:36 PM, threecuptea
> >> > <sonya_ling1947@yahoo.com>wrote:
> >> >
> >> >>
> >> >>
> >> >> My project is written in EJB3.  In  order to test EJB, I have a
> >> >> parentClass
> >> >> public abstract class EJBIntegrationTest with two BeforeSuites method
> >> >> @BeforeSuite(alwaysRun = true)
> >> >>    @Parameters({"deploy_beans_xml", "scan_classpath","jndi_name_emf",
> >> >> "jndi_name_usertx"})
> >> >>    public void startContainer(String deployBeansXml, String
> >> >> scanClasspath,
> >> >>                               String jndiNameEMF, String
> >> jndiNameUserTx)
> >> >>            throws Exception {
> >> >>
> >> >>        EJB3StandaloneBootstrap.boot(null);
> >> >>        EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
> >> >>
> >> EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/",
> >> >> File.separator));
> >> >>    }
> >> >> //Initialize environment for all subclass.
> >> >> @BeforeSuite(alwaysRun = true, dependsOnMethods="startContainer")
> >> >>    public void initialEnvironment() throws Exception {
> >> >>        jndi = new InitialContext();
> >> >>        programSession = lookupLocalBean(RemoteProgramSession.class,
> >> >> "ProgramSessionEJB");
> >> >>        metaSession = lookupLocalBean(LocalMetadataSession.class,
> >> >> "MetadataSessionEJB");
> >> >>        authoringSession =
> lookupLocalBean(LocalAuthoringSession.class,
> >> >> "AuthoringSessionEJB");
> >> >>        dashboardSession =
> lookupLocalBean(LocalDashboardSession.class,
> >> >> "DashboardSessionEJB");
> >> >>       EntityManager em =
> >> getEntityManagerFactory().createEntityManager();
> >> >>        session  = (Session) em.getDelegate();
> >> >>    }
> >> >>
> >> >> All EJB test classes extends EJBIntegrationTest with a BeforeClass
> >> method
> >> >> to
> >> >> prepare default testing variables like the followings:
> >> >> @Test(groups = "persistence-pandads-prgmgrp")
> >> >> public class ProgramSessionTest extends EJBIntegrationTest {
> >> >>
> >> >> @BeforeClass(groups="persistence-pandads-prgmgrp")
> >> >>    public void prepareSettings() {
> >> >>        dfltNetwork = programSession.getNetworkById(1);
> >> >>        dfltContentRating = programSession.getContentRatingById(5);
> >> >>        dfltProductType = programSession.getProductTypeById(2);
> >> >> :
> >> >> :}
> >> >>
> >> >> It works fine until I add a second EJB test class
> MetadataSessionTest.
> >> >> I
> >> >> found out prepareSettings method would always throws
> >> NullPointerException
> >> >> for whichever test class run second (test run in random order)
> because
> >> it
> >> >> is
> >> >> not able to access those EJBSession beans initialized in BeforeSuite
> >> >> method
> >> >> initialEnvironment.  prepareSettings method works fine for
> >> >> whichever test class run first.
> >> >>
> >> >> I tried many ways.  Finally, I get it work by changing
> >> >> initialEnvironment.
> >> >> to BeforeTest method.  (Test includes all test classes).
> >> >>  initialEnvironment
> >> >> seems to run once for each test class (It's not my original intent)
> >> >>
> >> >> I like to know
> >> >> 1) Why is the second test class unable to access variables
> initialized
> >> in
> >> >> before test suite method? I like to know the difference of
> >> implementation
> >> >> of
> >> >> BeforeSuite, BeforeTest, BeforeClass and how would that affect the
> >> >> running
> >> >> sequence and accessibility.
> >> >> 2) What should we put in beforeSuite, beforeTest, beforeClass in
> >> >> principle?
> >> >> What's your suggestion regarding to my case?
> >> >>
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26045430.html
> >> >> Sent from the testng-users mailing list archive at Nabble.com.
> >> >>
> >> >>
> >> >> >
> >> >>
> >> >
> >> >
> >> > --
> >> > Cédric
> >> >
> >> > >
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26064775.html
> >> Sent from the testng-users mailing list archive at Nabble.com.
> >>
> >>
> >> >
> >>
> >
> > >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/BeforeSuite%7CTest%7CClass-tp26045430p26066107.html
> Sent from the testng-users mailing list archive at Nabble.com.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: BeforeSuite|Test|Class

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Mon, Oct 26, 2009 at 2:29 PM, threecuptea <sonya_ling1947@...> wrote:
I attached BeforeSuite.log & BeforeTest.log  with my message posted at 11:21
AM.  Let me know if you can access them.
Judging from BeforeSuite.log,
It did call once in initialEnvironment() with @BeforeSuite.

Then I don't understand why you think this is an issue with TestNG(?).

--
Cédric



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: BeforeSuite|Test|Class

by threecuptea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The issue is that only the first running test class can access those sessionBean and EntityManageFactory retrieved in initialEnvironment() with @BeforeSuite.
All the following running test classes is unable to access them. That's why it throws NullPointerException.

I won't get the same trouble if I annotate initialEnvironment() with @BeforeTest.  I just like to know why.
Thanks.
Cédric Beust ♔ wrote:
On Mon, Oct 26, 2009 at 2:29 PM, threecuptea <sonya_ling1947@yahoo.com>wrote:

> I attached BeforeSuite.log & BeforeTest.log  with my message posted at
> 11:21
> AM.  Let me know if you can access them.
> Judging from BeforeSuite.log,
> It did call once in initialEnvironment() with @BeforeSuite.
>

Then I don't understand why you think this is an issue with TestNG(?).

--
Cédric

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Re: BeforeSuite|Test|Class

by Cédric Beust ♔ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Mon, Oct 26, 2009 at 3:12 PM, threecuptea <sonya_ling1947@...> wrote:


The issue is that only the first running test class can access those
sessionBean and EntityManageFactory retrieved in initialEnvironment() with
@BeforeSuite.
All the following running test classes is unable to access them. That's why
it throws NullPointerException.

I won't get the same trouble if I annotate initialEnvironment() with
@BeforeTest.  I just like to know why.

The only explanation I can think of (which, again, does not seem to be TestNG related) is that you are setting these variables to null some time after the first test has run.  This would explain why your test fails with @BeforeSuite but not if you use @BeforeTest (and again, I think you really want to use @BeforeMethod and not @BeforeTest).

--
Cédric



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@...
To unsubscribe from this group, send email to testng-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---