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

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

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.

TestNG Tutorials 25: Relation Between TestNG Annotations and TestNG XML

by Amod Mahajan time to read: 1 min
%d bloggers like this: