SELENIUM INTERVIEW QUESTION 6 – All Ways to Exclude/Ignore/Disable a Test Method in TestNG

Refer all Selenium interview question here.

Learn and share to reach it maximum.

When we integrate Selenium with TestNG, we create test methods using @Test annotation provided by TestNG. You can create test methods as many as you want. But sometimes you may need to ignore or disable test to exclude it while running as a suite , method or class level. We will see all ways to ignore a test method in this post.

We have three ways to ignore a test method:-

  1. Using @Ignore annotation of TestNG
  2. By setting “enabled” attribute as false for @Test annotated method
  3. By using “exclude” tag in testng xml

Let’s see every option in details.

Using @Ignore annotation of TestNG:

This is this latest feature provided by TestNG. I have already covered about it here. So I will not repeat it again here.

Ignore Annotation in TestNG

Difference between @Ignore and enabled attribute in TestNG

Ask me in comments if you have any doubt.

By setting “enabled” attribute as false for @Test annotated method:

This is traditional way and can be used if you are using older version of TestNG. “enabled” is an attribute of @Test annotation. Default value is always true to include it in run. You can set it false to exclude a particular test from running.

Output:-

By using “exclude” tag in testng xml:

Above two ways are good if you are doing at individual method or class level. But when you are running in a suite, it will be really difficult to manage at individual level. You may need to keep enabling or disabling tests. In that case you can use testng xml to manage it externally rather than modifying on method or class level. You can achieve easy scalability and modification if use enabling disabling test using testng xml.

Testng xml:-

Output:-

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

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.
%d bloggers like this: