|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
BeforeSuite|Test|ClassMy 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|ClassA few thoughts.
-- Cedric On Sat, Oct 24, 2009 at 10:36 PM, threecuptea <sonya_ling1947@...> wrote:
-- 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|ClassBeforeSuite.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>
|
|
|
Re: BeforeSuite|Test|ClassI'm sorry I don't understand what you are saying.
How about you
-- Cédric On Mon, Oct 26, 2009 at 11:21 AM, threecuptea <sonya_ling1947@...> wrote:
--~--~---------~--~----~------------~-------~--~----~ 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|ClassEJBIntegrationTest.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.
|
|
|
Re: BeforeSuite|Test|ClassSo 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:
--~--~---------~--~----~------------~-------~--~----~ 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|ClassI 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.
|
|
|
Re: BeforeSuite|Test|ClassOn Mon, Oct 26, 2009 at 2:29 PM, threecuptea <sonya_ling1947@...> wrote:
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|ClassThe 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.
|
|
|
Re: BeforeSuite|Test|ClassOn Mon, Oct 26, 2009 at 3:12 PM, threecuptea <sonya_ling1947@...> wrote: --
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 -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |