Building a Test Suite in TestNG

In the previous post, we have learnt how to write a program in TestNG. In this post, we will see what is a TestSuite and its usage in TestNG.

What is a Test Suite?

In any project, you will have a bunch of test cases. In the previous post, we have seen how to execute a single program. What is , we need to execute the whole bunch of test cases altogether in TestNG. This will be possible by building a Test Suite in TestNG. Or in other words, you can say Test Suite is a XML file that includes the set of test cases which need to be executed.

TestNG provide a way to manage test execution. Those test cases may be dependent on each other or follow a certain execution order. You will create one testng.xml file to include all the test classes, packages, methods, parameters if required etc. (A pictorial presentation is given below having the attributes in Test Suite.)

TestSuite in TestNG


A basic structure of a testng.xml file:

This basic testng.xml given below contains the classes and its packages.


Let’s understand step by step working of Test Suite:

Step#1 Right click on the project folder –> New –> File.

Create testng xml file

 

Step#2 A new window will open , give the name as testng.xml and click finish.

Save as testng xml

 

Step#3 It will create a new file where you can add classes that need to be executed. Suppose, we need to add the class as shown below in the figure.

Add class in testng suite

 

Step#4 Add the class into testng.xml (Test Suite).

step#5 To run the Test Suite , right click on testng.xml –> Run As –> TestNG Suite.

Run Test Suite in testNG

The class that is included in Test Suite.

 

Step#6 After running test suite, Test class will be executed and you will get the below output.

In console: 

TestNG output

Result of running Suite:

TestNG result

 


Building a Test Suite in TestNG including multiple classes:

Suppose, we have multiple Test classes. We can add those classes to the Test Suite as shown in the figure below.

Adding More classes in test suite

 

After running the whole suite , you will see the following output.

Test Suite output


 

Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum
Print Friendly, PDF & Email
Writing First Program with TestNG
Execution Sequence of Annotations in TestNG
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

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