TestNG Tutorials 8: Understanding Testng.xml : Understanding Hierarchy Of Testng.xml

Hello Folks,

In this post, we will see a very important and basic concept of TestNG : Understanding of TestNG.xml

You must aware about the hierarchy of testng.xml to implement many concept of testng. Let’s learn it:

I will generate a testng.xml for below hierarchy of project:

The generated testng.xml will be as below. I have added some extra tags for better understanding.

When we generate a testng.xml by default, it includes all methods annotated with @Test tag of a class. That is the reason you do not see  tag. I added to make you understand about hierarchy of testng.xml in above xml.

There are five levels in a testng.xml as marked in red border in above image:

  1. Method
  2. Classes
  3. Class
  4. Test
  5. Suite

You can relate all above levels with Testing Methodologies as below:

A project is divided in to different Modules. Each module is divided in to multiple Test Scenarios. Each test scenario is divided in to multiple Test Cases. Since TestNG is a testing framework, it also allows you to organize your test as you do as a manual tester. You can categorized your automation suite in same way as you do in manual testing.

  1. Method  : Test Cases
  2. Class       : Test Scenarios
  3. Classes   : Module Testing
  4. Test        : Integration Testing
  5. Suite      : System Testing

These level allows you to do extra setup for a test or module or suit. We will see more in upcoming posts, how knowledge of levels in testng.xml is going to help us.

A suite(Project) can have multiple Tests(Modules). A Test can have multiple Classes ( Please note here I am talking about tag not . You can have only single tag in a tag).

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below. If you like my posts, please like, comment, share and subscribe. #ThanksForReading

#HappySelenium