Test Suites are a combination of one or more classes (class files) and programs. Test Suite is basically an XML file, used to group and organize the test cases from different class files.
Till now we have seen that we can run Test Cases written in any class file directly using Right Click on that Class file. But in real scenarios, we have to write hundreds of files to create any framework. In that case, we have to use Test Suites to manage and organize these Test Cases for execution. Will learn the same in further blogs.
In this chapter will see the basic structure of XML, execution process and result analysis using only one Class file.

Test Suites XML Structure
Steps to Create TestNG XML File
- Select Project > Right Click on Project
- Click New > Other
- Search for TestNG and expand it
- Click on TestNG class > Next
- Select the Source(src) folder of the project.
- Click to select Package under the src folder “testSuitePackage“.
- Give any name in the ‘Class Name’ field “LoginPage“.
- Type XML file name in the ‘XML Suite file’ field “Simple_TestSuite.xml’
LoginPage.java
package testSuitePackage;
import org.testng.annotations.Test;
/**
* @author ashok.kumar
*/
public class LoginPage {
@Test
public void launchURL()
{
System.out.println("URL Launched Successfully.");
}
@Test(dependsOnMethods="launchURL")
public void login()
{
System.out.println("User Logged-In Successfully.");
}
@Test(dependsOnMethods="login")
public void changeProfile()
{
System.out.println("User Profile changed Successfully.");
}
@Test(dependsOnMethods="login")
public void deactivateSubscription()
{
System.out.println("Subscription deactivated successfully.");
}
@Test(dependsOnMethods="login")
public void logout()
{
System.out.println("User Logged-out Successfully.");
}
}
Simple_TestSuite.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="SimpleSuiteExample" parallel="false">
<test name="AlphaTestCases">
<classes>
<class name="testSuitePackage.LoginPage"/>
</classes>
</test>
</suite>
All the rules which we have learned about priority, alphabetical order, beforeMethod, before class will remain the same for each Test set.
Executing the Multiple Test cases
- Right click on the XML file “Simple_TestSuite.xml“
- Select on RunAs
- Click on TestNG Suite
Result Analysis wrt XML file
The above test suite will execute all the test-cases (methods) coded in the LoginPage.java file. The output result of the program can be seen using the console of the Eclipse.
To view the HTML result after execution, refresh the test-output folder in the Project Explorer navigation. Observe that a new folder with the suite name “SimpleSuiteExample” is created as like

It includes the result of each test, which we have defined as test name “AlphaTestCases” and so on. The result in the index.html and emailable-report.html would be analyzed as we have discussed in the second Chapter.
Tags in Test Suites
In the above example, all the methods get executed, but what if we want to perform a regression/smoke and want to run only specific Test Cases from the entire program. We can achieve the same with few modifications in our existing Test Suite XML File.
<?xml version="1.0" encoding="UTF-8"?>
<suite name="SimpleSuiteExample" parallel="false">
<!-- <test name="AlphaTestCases">
<classes>
<class name="testSuitePackage.LoginPage"/>
</classes>
</test> -->
<test name="RegressionTestCases">
<classes>
<class name="testSuitePackage.LoginPage"/>
<methods>
<include name="login"/>
<include name="launchURL"/>
<include name="logout"/>
</methods>
</classes>
</test>
</suite> <!-- Suite -->
See above example, we have added new section <test name=”RegressionTestCases”> in the xml file. This new section contains <include> tags to determine which methods need to be executed from the entire class file.
- <?xml>: XML standard tag which needs to be use by default.
- <suite name=”String”>: Defines the name of the Suite.
- <test name=”String”>: Define the Test Case Name in a Test Suite.
- <classes>: Contains list of all class files for execution. It can have multiple class tags.
- <class name=”packageName.className”>: Contains reference of one class file including respective package name.
- <methods>: If we don’t use this tag all the methods having @Test annotation will be executed. But in case we have to run only few methods from a class we could define the same under this tag.
- <include name=”methodName”>: This tag defines the name of each method used in a class.
Make sure to comment AlphaTestCases section otherwise both the tests would run. Now run the test suite xml file and will observe that only the methods mentioned under <include> tag executed.
Result Analysis with Two Tests
If we run the above Test Suite XML file without commenting any Test, we will observe below changes in the test-output folder. Now there would be two HTML files present, containing the result for each Test.

The emailable-report.html will look like below sample.

Related Links:
- TestNG – 1 || Introduction and benefits of TestNG Framework.
- TestNG – 2 || Installation process and a sample program of TestNG.
- TestNG – 3 || Create and execute multiple Test Cases.
- TestNG – 4 || Let’s understand @Test Annotation and attributes.
- TestNG – 5 || Understand Assertion in TestNG.
- TestNG – 6 || Use of @BeforeMethod and @AfterMethod.
- TestNG – 7 || Use of @BeforeClass and @AfterClass.
- TestNG – 8 || Creation and execution of Test Suites.
- TestNG – 9 || Let’s move deep into the Test Suites.
- TestNG – 10 || Use @BeforeTest and @AfterTest Annotations.
- TestNG – 11 || Groups attribute with @Test Annotation.
- TestNG – 12 || Use of @BeforeGroups & @AfterGroups.
- TestNG – 13 || Use of @BeforeSuite & @AfterSuite.
- TestNG – 14 || DataProvider annotation & attribute.
- TestNG – 15 || DataProvider with parameters.
- TestNG – 16 || Access data from Excel sheet using DataProvider.
- TestNG – 17 || Passing multiple Parameters in testng xml.
- TestNG – 18 || Multiple Browser and Parallel Execution in TestNG.
- TestNG -19 || Concept of Parallel Execution.
- TestNG – 20 || Run TestNG Program using main() method.
Java Basics:
- Basic Java – 1 || Understand Java before start learning JAVA.
- Basic Java – 2 || Variables and Data Types used in JAVA.
- Basic Java – 3 || Understanding Class, Objects, Methods in Java.
- Basic Java – 4 || More on methods(Return Type and Parameters)
- Basic Java – 5 || Methods- Call by Value and Call by Reference in Java.
- Basic Java – 6 || Understanding of Constructor and Destructor in JAVA.
- Basic Java – 7 || Static Variables and Methods.
- Basic Java – 8 || Lets learn about Arrays in Java.
- Basic Java – 9 || Performing multiple operations using Java Operators.
- Basic Java – 10 || Conditions (If and Switch) in JAVA.
- Basic Java – 11 || for and for-each in Java. (Loops Part-1)
- Basic Java – 12 || Alternate looping concepts while and do-while. (Loops Part-2)
- Basic Java – 13 || Decimal values v/s Octal base(8) values in JAVA.
- Basic Java – 14 || Learn about String literals in Java.
- Basic Java – 15 || Runtime User Input using Scanner Class (Part-1).
- Basic Java – 16 || Runtime User Input using BufferedReader Class (Part-2).
- Basic Java – 17 || Runtime User Input using Console Class (Part-3).
- Basic Java – 18 || Difference between break and continue keywords.
- Basic Java – 19 || Sending Email using Java (Part-1).
- Basic Java – 20 || Sending Email with attachment using Java (Part-2).
- Basic Java – 21 || Stack memory and Heap memory in Java.
- Basic Java – 22 || Let’s learn more about String.
- Basic Java – 23 || String, StringBuffer & StringBuilder in Java.
- Basic Java – 24 || Exception Handling using Try Catch.
- File Handling | Reading data from word document(.doc or .docx) in JAVA.
- File Handling | Reading data from Excel files (.xls or .xlsx) using JAVA.
- File Handling | Writing data into an Excel(.XLSX or .XLS) File.
- File Handling | Implement formatting in Excel using Java.
- File Handling | Copy existing data from one workbook to another workbook in Java.
- File Handling | Reading data from PDF file using JAVA.
- File Handling || Traverse folders and subfolders in Java.
- File Handling || Reading and Writing data from a text file.
- File Handling || Multiple file creation using template based input data.
- Framework || Simple example of Key Driven Framework using excel sheet in Selenium(JAVA).
- QnA || How to use Constructors in Abstract class?
- QnA | Difference between Integer and int keywords.
- QnA | Can main method be overloaded?
- QnA | How do I reverse a String/Sentence in Java?
- QnA | Perform Multiplication and Division without * or / or % operators.
- QnA | How do I get the default value of data type?
- QnA | How to split String if it contains period symbol (.) in between?
- Different ways to Reverse a String in Java.
- Copy formatting & style of cells from one sheet to another.
- Getting IP address and Hostname using InetAddress Class.
- User inputs via Command Prompt using arguments of main() method of a class.
- Program for List and ArrayList in Java.
- Useful methods and implementation under Scanner Class.
- Swapping two variable values without using any third variable.
- Difference between int x= 10 and y=010 in Java.
- Parameterized Constructors v/s Setter and Getter function in JAVA.
- Override a Static Method.
- Computer Basics -13 || Creating pivot charts/tables in Excel.
- Computer Basics -12 || Advantages of PivotCharts over Simple Charts in Excel.
- Computer Basics -11 || Using Charts in place of Data Tables in Excel.
- Computer Basics -10 || How to apply Filter in a data set in Excel?
- Computer Basics -9 || Understand and Implement Data Validation in Excel.
- Computer Basics -8 || Let’s learn the usage of MS-Excel.