When running TestNg with groups it is skipping @BeforeClass and @BeforeSuite methods. however running without group it execute @BeforeClass and @BeforeSuite
Code :
class TestStructure {
@BeforeClass
public void loadData() {
System.out.println("loaded");
}
@BeforeSuite
public void loadSysData() {
System.out.println("loaded2");
}
}
class Test extends TestStructure
{
@Test(groups={"UAP"})
public void test1
{
System.out.println("Test 2");
}
}
The testng.xml
file is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="UAP suite" parallel="false" thread-count="1" verbose="1">
<listeners>
<listener class-name="com.module.listener.TestNGListener" />
</listeners>
<test name="TestSet 1" parallel="false" preserve-order="true">
<groups>
<run>
<include name="UAP" />
</run>
</groups>
<classes>
<class name="Test" />
</classes>
</test>
</suite>
If I remove group from the xml then @BeforeClass
and @BeforeSuite
are executed.
Please help.
There are two options you need to consider in order to resolve this issue.
alwaysRun=true
for all your beforeXXX & afterXXX methods. If you want these methods to run irrespective of group being testedgroups
. Based on your use case, you need update your annotations to either
@BeforeClass(alwaysRun=true)
and @BeforeSuite(alwaysRun=true)
or
@BeforeClass(groups={"UAP"})
and @BeforeSuite(groups={"UAP"})
Hope this answers your question.
For further Reference - http://testng.org/doc/documentation-main.html#annotations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With