TestNG Tutorials 66 : Ignoring Tests in TestNG Using New Annotation @Ignore

Hello Folks,

TestNG provides an attribute called “enabled” which can be used to ignore a test in a running suite. If we use this attribute at class level with @Test annotation, it will ignore all tests of that class.

Now TestNG is providing a new annotation called “@Ignore”, which can be used to ignore :

  1. A specific @Test annotated method.
  2. All @Test annotated methods of a class and its child class
  3. All @Test annotated methods of a package and its sub package.

Ignoring/disabling a specific @Test annotated method:

We can ignore a particular @Test annotated method setting “enabled” as false at @Test annotation. Now the same we can achieve using @Ignore attribute. Example is shown below:

Output:

[RemoteTestNG] detected TestNG version 6.14.2
I am an active test.

===============================================
Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Ignoring/disabling all @Test annotated methods of a class and its subclass:

Now we can easily ignore all @Test annotated method of a Class and its subclass using @Ignore annotation. However same can be achieved using @Test(enabled= false) annotation at class level. An example is below:

Super Class:

Sub Class:

You can notice I put @Ignore annotation at super class. It will disable test from base class and its child class. NOte here that this feature is available in TestNG Release 6.14.3 onwards.

Output:

[RemoteTestNG] detected TestNG version 6.14.3

===============================================
    Default test
    Tests run: 0, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 0, Failures: 0, Skips: 0
===============================================

Ignoring/disabling all @Test annotated methods of a package and its subpackages:

Like method and class, we can not put @Ignore annotation on top of package statement of a class as Package does not belong to class. So to ignore all @Test annotated method of a package and its subpackage, we need to mention @Ignore annotation in “package-info.java”. You can create a “package-info.java” file while creating a package by selecting a checkbox or you can create manually and place inside package.

You need to place @Ignore annotation on top of package statement as shown below:

It will ignore all @Test annotated methods of package named “IgnoreExamples”.

Hope you must have learnt new thing of TestNG today.

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: