I’m currently experiencing a problem. I created 2 classes, one is abstract, the other one is inherited from the first one:
public abstract class A {
@BeforeClass
protected void setUp() {
Object o = new Object();
}
@AfterClass
protected void tearDown() {
o = null;
}
@Test
public void T1() {
// whatever is done here
}
@Test(dependsOnMethod={"T1"})
public void T2() {
// whatever is done here
}
}
@Test(singleThreaded=true)
public class B extends A {
@Test(dependsOnMethod={"T2"})
public void T3() {
System.out.println(o.toString());
}
}
Actually, I got 2 different behaviours between Eclipse & Jenkins.
When I run my test under Eclipse, the execution order is:
setUp()
T1()
T2()
T3()
tearDown()
But under Jenkins, the execution order is:
setUp()
T1()
T2()
tearDown()
T3()
As a result, in the second case, T3() obviously fails, due to a NullPointerException as the Object o has been destroyed by the tearDown() method.
TestNG is called by Jenkins, by using the maven-surefire-plugin, by specifying a testng.xml file. Here it is:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestSuite" parallel="classes" thread-count="1" verbose="1">
<test name="Test B">
<classes>
<class name="main.pkg.B" />
</classes>
</test>
</suite>
Is there a way to make both Jenkins & Eclipse have the same behaviour ?
If so, any help would be very appreciated.
Regards,
Cedric
It may be that your testng plugin version in eclipse is different than the one in your project.
When you run via jenkins using maven, it uses the testng dependency from your pom. Whereas in eclipse you may have configured some other testng plugin version which is used for the eclipse runs.
I have 6.5.1 as testng dependency version in pom and 6.5.2 of the plugin version and I get the correct output from both. I earlier had testng 6.2.1 as my maven dependency and I could see the issue that you are seeing. So probably matching both versions may help.