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 <method> tag. I added <method> 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 <class> tag not <classes>. You can have only single <classes> tag in a <test> 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

5 thoughts on “TestNG Tutorials 8: Understanding Testng.xml : Understanding Hierarchy Of Testng.xml

  1. Hi Amod. The concept above isnt clear about what it is trying to explain. can you make it more clear for understanding purpose?

    1. Hello,
      It about structure of xml. Like suite contains test which contains classes and methods. A suite can have multiple tests. Just try to compare it with your manual effort of organising test cases.

Leave a Reply to Amod Mahajan Cancel reply

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