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.
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.
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.