Styrow.dev
Question 12 of 14
TestNG Topic: General medium

How do you execute group test cases in TestNG?

Question

How do you execute group test cases in TestNG?

Answer

We can execute only set of group and exclude another set. This gives us the maximum flexibility in divide tests and doesn’t require us to recompile anything if you want to run two different set of tests back to back. Groups are specified in testng.xml file.

Sample Code:

public class groupExamples{

@Test(groups""=Regression"") public void testCaseOne(){ System.out.println(""Regression Group""); }

@Test(groups""=Regression"") public void testCaseTwo(){ System.out.println(""Regression Group""); }

@Test(groups""=Retest"") public void testCaseThree(){ System.out.println(""Retest Group""); }

@Test(groups""=Regression"") public void testCaseFour(){ System.out.println(""Retest Group""); } }