Make Selenium Easy

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

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.