Test Suites widely used to organize and execute test cases from multiple class files. It also helps to create various test sets using these classes and methods.

To understand this, we need to create different class files. Let’s create below class files using specific methods.
- LaunchAndLogin.java
- launchBrowser()
- launchURL()
- login()
- MyOrders.java
- viewOrders()
- placeOrder()
- MyProfile.java
- editProfile()
- saveProfile()
- viewProfile()
- LogoutAndClose.java
- logout()
- closeBrowser()
Test Suites using multiple Classes
LaunchAndLogin.java
package testSuitePackage;
import org.testng.annotations.Test;
/**
* @author ashok.kumar
*/
public class LaunchAndLogin
{
@Test
public void launchBrowser()
{
System.out.println("Browser launched successfully.");
}
@Test
public void launchURL()
{
System.out.println("WebSite launched successfully.");
}
@Test
public void login()
{
System.out.println("User Logged-In using valid credentials.");
}
}
MyOrders.java
package testSuitePackage;
import org.testng.annotations.Test;
/**
* @author ashok.kumar
*/
public class MyOrders {
@Test
public void viewOrders()
{
System.out.println("My Orders page get opened.");
}
@Test (dependsOnMethods="viewOrders")
public void placeOrder()
{
System.out.println("New item added to the My Orders.");
}
}
MyProfile.java
package testSuitePackage;
import org.testng.annotations.Test;
/**
* @author ashok.kumar
*/
public class MyProfile {
@Test
public void editProfile()
{
System.out.println("Changes updated in the Profile.");
}
@Test
public void saveProfile()
{
System.out.println("Profile saved successully.");
}
@Test
public void viewProfile()
{
System.out.println("Profile page get opened.");
}
}
LogoutAndClose.java
package testSuitePackage;
import org.testng.annotations.Test;
/**
* @author ashok.kumar
*/
public class LogoutAndClose
{
@Test
public void logout()
{
System.out.println("User logged out successfully.");
}
@Test (dependsOnMethods="logout")
public void closeBrowser()
{
System.out.println("Browser Closed.");
}
}
Updated_TestSuite.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="UpdatedSuiteExample" parallel="false">
<test name="AlphaTestCases">
<classes>
<class name="testSuitePackage.LaunchAndLogin"/>
<class name="testSuitePackage.MyOrders"/>
<class name="testSuitePackage.MyProfile"/>
<class name="testSuitePackage.LogoutAndClose"/>
</classes>
</test>
</suite> <!-- Suite -->
Result Analysis

index.html (chronological order)

Creating Multiple Test Sets using Multiple Classes
Suppose, as per requirement we have to create different Test Sets for Alpha Round, Smoke Test and UAT using all the four classes and methods. We can distribute the test methods as mentioned below table:
Test Set | AlphaTestCases | SmokeTestCases | UATTestCases |
Test Case Count | 10 | 7 | 5 |
Class Names | LaunchAndLogin MyOrders MyProfile LogOutAndClose | LaunchAndLogin MyOrders MyProfile LogOutAndClose | LaunchAndLogin MyOrders MyProfile |
Method Names | launchBrowser() launchURL() login() placeOrder() viewOrders() editProfile() saveProfile() viewProfile() logout() closeBrowser() | launchBrowser() launchURL() login() viewOrders() editProfile() saveProfile() logout() | launchBrowser() launchURL() login() viewOrders() viewProfile() |
To Create these Test Sets we have to modify our XML file as mentioned below:
<?xml version="1.0" encoding="UTF-8"?>
<suite name="UpdatedSuiteExample" parallel="false">
<test name="AlphaTestCases">
<classes>
<class name="testSuitePackage.LaunchAndLogin"/>
<class name="testSuitePackage.MyOrders"/>
<class name="testSuitePackage.MyProfile"/>
<class name="testSuitePackage.LogoutAndClose"/>
</classes>
</test>
<test name="SmokeTestCases">
<classes>
<class name="testSuitePackage.LaunchAndLogin"/>
<class name="testSuitePackage.MyOrders">
<methods>
<include name="viewOrders"></include>
</methods>
</class>
<class name="testSuitePackage.MyProfile">
<methods>
<include name="editProfile"></include>
<include name="saveProfile"></include>
</methods>
</class>
<class name="testSuitePackage.LogoutAndClose">
<methods>
<include name="logout"></include>
</methods>
</class>
</classes>
</test>
<test name="UATTestCases">
<classes>
<class name="testSuitePackage.LaunchAndLogin"/>
<class name="testSuitePackage.MyOrders">
<methods>
<include name="viewOrders"></include>
</methods>
</class>
<class name="testSuitePackage.MyProfile">
<methods>
<include name="viewProfile"></include>
</methods>
</class>
</classes>
</test>
</suite> <!-- Suite -->
Result Analysis



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.