Write a TestNG test method to categorize into groups using TestNG and control which groups are to be executed.
Create new TestNG class named “GroupTestDemo”.
Create 3 test methods ‘groupATest()’, ‘groupBTest()’, ‘groupBothTest()’.
Categorize these methods into groups: ‘groupATest()’ to group “A”, ‘groupBTest()’ to group “B” and ‘groupBothTest()’ to both groups.
Configure the XML file to run only the “A” group. Execute the test suite and observe that only two methods run.
package practice;
import org.testng.annotations.Test;
public class GroupTestDemo {
@Test(groups = "A")
public void groupATest() {
System.out.println("This is Group A");
}
@Test(groups = "B")
public void groupBTest() {
System.out.println("This is Group B");
}
@Test(groups = {"A","B"})
public void groupBothTest() {
System.out.println("This is Group A and Group B both");
}
}
<suite name=”Suite”>
<test name="GroupATests">
<groups>
<run>
<include name="A"/>
</run>
</groups>
<classes>
<class name="testngNotes.Names"></class>
</classes>
</test>
</suite>
Copyright © 2023 - Proleed Academy | All Rights Reserved.