Grouping test cases in TestNG:

 

  • We can group multiple test methods in a named group.
  • You can easily classify your test cases based on requirement.
  • You can perform a specific group of test methods related to a group or multiple groups.
  • You can create a group of test methods based on the testing type, depending on modules or based on testing types like functional testing, sanity testing etc…
  • Differentiate specific group test methods from all test methods.

 

Grouping Syntax:

Grouping Example:

 

Scenario’s:

  • Before each and every method we use @Test(groups = { “sanity” }) method.
  • Using groups method we provide multiple group names.
  • As per group names execute methods from class.

 

Example: Grouping test cases in TestNG:

 

Running a TestNG group through testng.xml:

 

1. Execute single group using TestNG.xml file e.g. sanity

  • If we want to execute only one group from class using TestNG.xml file.
  • Then add group name into TestNG.xml file then run TestNG. xml file.

 

Note:  Right click on testng.xml and run it as testng suite.

 

2. Execute Multiple groups using TestNG.xml file e.g. smoke / sanity

  • If we want to execute Multiple group’s from class using TestNG.xml file.
  • Then add Multiple group name’s into TestNG.xml file then run TestNG. xml file.

Note:  Right click on testng.xml and run it as testng suite to execute / run Script.

How to skip tests using TestNG and TestNG Annotations, Groups & OnDepends Annotations