Reputation: 11
I want to distinguish test API in to 2 groups and run any one group in the testng xml based on the requirement.
But the method mentioned in the include tag always gets executed irrespective of the Groups. Is there any way i can achieve this functionality in TestNg, since i cant avoid the include tag.
My Test class and the corresponding xml is as follows;
package com.eci.raft.tests.shadetree;
import java.io.IOException;
import org.testng.annotations.Test;
public class TestClass {
@Test(groups= {"WithOuthardware","Withhardware"})
public void configureApi() {
System.out.println("Configure");
}
@Test(groups= {"Withhardware"})
public void validateApi() throws IOException {
System.out.println("Validate");
throw new IOException();
}
}
TestNg.xml
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SuiteTest">
<groups>
<run>
<include name="WithOuthardware"></include>
</run>
</groups>
<test name="Test1" >
<classes>
<class name="com.eci.raft.tests.shadetree.TestClass">
<methods>
<include name="validateApi"></include>
</methods>
</class>
</classes>
</test>
<test name="Test2">
<classes>
<class name="com.eci.raft.tests.shadetree.TestClass">
</class>
</classes>
</test>
</suite>
Here "validateApi" in the "Test1" gets executed even though it is not tagged with "WithOuthardware" group name.
Thanks and regards,
Venkatesh Ganesan
Upvotes: 1
Views: 2947
Reputation: 114
I believe the issue was with your xml, it is kind of conflicting as it explicitly including the method you don't want to include. You can simplify it and remove the conflict by just providing the class, try this for your xml and see if it works for you.
<suite name="SuiteTest">
<groups>
<run>
<include name="WithOuthardware"></include>
</run>
</groups>
<test name="Test" >
<classes>
<class name="com.eci.raft.tests.shadetree.TestClass">
</class>
</classes>
</test>
</suite>
Upvotes: 0
Reputation: 2814
Not sure if i understand correctly the question but you can try something like that.
<test name="Some random test">
<groups>
<run>
<include name="group1" />
<include name="group2" />
</run>
</groups>
<classes>
<class name="com.eci.raft.tests.shadetree.TestClass" />
</classes>
</test>
<test name="Some random test 2">
<groups>
<run>
<include name="group2" />
</run>
</groups>
<classes>
<class name="com.eci.raft.tests.shadetree.TestClass" />
</classes>
</test>
You can play with the groups/priority/dependency of the tests.
@Test(groups={"group1"}, priority=0)
@Test(groups={"group2"}, dependsOnGroups="groupX", priority=1)
Let us know if there is something else to help.
Upvotes: 0