Make Selenium Easy

TestNG Tutorials 25: Relation Between TestNG Annotations and TestNG XML

Hello Folks,

In last post, we have seen available annotation in TestNG.

Beginner and experienced professionals are always confused in understanding order of execution of annotated methods and usage. In this post, I will try to help you in understanding this concept better. I will recommend to read this post first which explains hierarchy of testng xml.

All annotations provided by TestNG is directly related to testng.xml tags. TestNG XML has four major tags:

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

So, TestNG provides you annotations at these levels which can be used for prerequisite and post requisites setup as a whole or individual.

SuiteBeforeSuite, AfterSuite
TestBeforeTest, AfterTest
MethodBeforeMethod, AfterMethod

Please note:

  1. A testng xml can have single <suite> tag.
  2. You can have multiple <test> tags in a <suite> tag.
  3. You can have single <classes> tag in a <test> tag.
  4. You can have multiple <class> tag inside a <classes> tag.
  5. You can have multiple test method (@Test annotated) names inside <methods> tag inside a <class> tag.

Below xml explains when TestNG annotated methods will be called:

Hope, above xml will help you in understand calling of TestNG annotated methods.

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.

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.