TestNG – 8 || Creation and execution of Test Suites.

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.

Simple Suite Example
Simple Suite Example

Test Suites XML Structure

Steps to Create TestNG XML File

  1. Select Project > Right Click on Project
  2. Click New > Other
  3. Search for TestNG and expand it
  4. Click on TestNG class > Next
  5. Select the Source(src) folder of the project.
  6. Click to select Package under the src folder “testSuitePackage“.
  7. Give any name in the ‘Class Name’ field “LoginPage“.
  8. Type XML file name in the ‘XML Suite file’ field “Simple_TestSuite.xml


package testSuitePackage;
import org.testng.annotations.Test;

 * @author ashok.kumar
public class LoginPage {
	public void launchURL()
		System.out.println("URL Launched Successfully.");
	public void login()
		System.out.println("User Logged-In Successfully.");
	public void changeProfile()
		System.out.println("User Profile changed Successfully.");
	public void deactivateSubscription()
		System.out.println("Subscription deactivated successfully.");
	public void logout()
		System.out.println("User Logged-out Successfully.");


<?xml version="1.0" encoding="UTF-8"?>
<suite name="SimpleSuiteExample" parallel="false">
 <test name="AlphaTestCases">
      <class name="testSuitePackage.LoginPage"/>

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

  1. Right click on the XML file “Simple_TestSuite.xml
  2. Select on RunAs
  3. 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 nameSimpleSuiteExample” is created as like

test-output folder

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">
      <class name="testSuitePackage.LoginPage"/>
  </test>  -->
  <test name="RegressionTestCases">
      <class name="testSuitePackage.LoginPage"/>
      <include name="login"/>
      <include name="launchURL"/>
      <include name="logout"/>

</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.

test-output folder

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


Related Links:

Java Basics:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:


Leave a Comment

Your email address will not be published. Required fields are marked *

   YouTube ChannelQuora

            Ashok Kumar is working in an IT Company as a QA Consultant. He has started his career as a Test Trainee in manual testing in August 2010. Then he moves towards the automation testing after 4 years. He started learning JAVA and Selenium by self to get the knowledge of automation.

       While learning these tools and working on multiple projects, he found that sometimes people get stuck in live scenarios in their project and they have to do lots of RnD to get out of it. So he decided to start blogging only for such scenarios, where anyone facing any problem in their project, can ask any question or give a solution or you can say an alternate solution to achieve the goal successfully.

Later on, he observed that some people want to learn Java but they have few questions in their mind like how to start Java, whether we should go for the online or offline course. So he started writing tutorials on Java, Jira, Selenium, Excel etc.