TestNG-J test doesn't instantiate super class

Hi,

I have this class :

public class SpringBaseTest {
protected ApplicationContext ctx;
protected ServiceFacade facade;

@BeforeSuite
public void setUp() throws IOException {
ctx = new ClassPathXmlApplicationContext(new String [] {"application-context.xml",
"application-datasource.xml"});
facade = (ServiceFacade) ctx.getBean("serviceFacade");
}
}

and my test class like this :

public class NgPartnerTest extends SpringBaseTest {

@Test(groups = {"testPartner"})
public void testBlabla() {}
}

When launching a test suite with the plugin and this testng.xml file :

]]>

I get a NullPointerException telling me that facade is null. Indeed it is null because when I try to debug and see what happens in SpringBaseTest, it doesn't even stop at the breakpoint I've put inside the setUp() method !

Have I missed something ?

2 comments
Comment actions Permalink

Interesting - I'll take a look and see whats going on. I do something
similar but instead of @BeforeSuite I use @BeforeGroup on a 'spring' group.

Initially I had thoughts that the @BeforeSuite may have run on its own
instance of SpringBaseTest separate from the instance of NgPartnerTest
for the @Test but if the setups not even running I'm not sure..

I'll setup a project with this setup and see whats going on..

Mark
That TestNG-J guy...


Bruno Dusausoy wrote:

Hi,

I have this class :

public class SpringBaseTest {
protected ApplicationContext ctx;
protected ServiceFacade facade;

@BeforeSuite
public void setUp() throws IOException {
ctx = new ClassPathXmlApplicationContext(new String [] {"application-context.xml",
"application-datasource.xml"});
facade = (ServiceFacade) ctx.getBean("serviceFacade");
}
}

and my test class like this :

public class NgPartnerTest extends SpringBaseTest {

@Test(groups = {"testPartner"})
public void testBlabla() {}
}

When launching a test suite with the plugin and this testng.xml file :

<suite name="MMS Election Tool">
<test name="Partner">
<groups>
<run>
<include name="testPartner"/>
</run>
</groups>
<packages>
<package name="bla.services"/>
<package name="bla.bo"/>
<package name="bla.dao"/>
</packages>
<classes>
<class name="bla.SpringBaseTest"/>
<class name="bla.NgPartnerTest"/>
</classes>
</test>
</suite>

I get a NullPointerException telling me that facade is null. Indeed it is null because when I try to debug and see what happens in SpringBaseTest, it doesn't even stop at the breakpoint I've put inside the setUp() method !

Have I missed something ?

0
Comment actions Permalink

The problem lies with the suite file....

By adding the element you're telling TestNG to only run methods in the testPartner group. Unfortunately (and this is one my pet-hates with TestNG) is that this is -all- methods, not just test methods. You @BeforeSuite method doesn't have a group parameter and so isn't included in the run. It would be nice if TestNG pulled in the implicit methods, but I can also see reasons for keeping things explicit. Oddly - another problem I found was that specifyig the two classes also didn't work, however - changing it to "bla.*" using a wildcard did. Mark >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> ]]>

0

Please sign in to leave a comment.