@Test(Enabled=false) lets you ignore tests in Selenium TestNG

When we are working in Test automation project then we come across a situation where some of our tests are still in progress, that is not in a ready state to commit the code. We get torture from our manager that ‘show and tell’ is scheduled hence we are preparing to present in front of clients in whatever phase we are in. Therefore, in such a situation, we can ignore tests which are not in ready state and could go with the scenarios which are in ready state.

We got the go-ahead signal from the manager, but technically we have to deal with the situation to avoid the rework. Our agenda for this tutorial is very much clear now. We will discuss the technique to ignore tests in Selenium WebDriver with the help of TestNG.

Yes, you got it right!

TestNG has the inbuilt feature to ignore the specific tests which we do not want to execute. It’s really quite fascinating to work using the TestNG framework, Isn’t it?

Before we jump to the discussion on TestNG ignore tests feature, let’s have a look at previous tutorials on TestNG:

How to implement ignore tests feature of TestNG in Selenium WebDriver project?

We got the background to use ignore tests feature of the TestNG. Now let’s discuss the implementation of this feature in our Selenium WebDriver project. So, to ignore tests we need to use enabled=false with any of the @Test annotations. Wherever, enabled=false, mentioned then the compiler will automatically understand that this @Test annotation will not be executed, hence, it will be ignored.

Therefore, simply use @Test(enabled=false), if you want to ignore that particular test.

Sample Program

Here is the sample program where we have implemented ignore tests feature of TestNG.

package Test;

import org.testng.annotations.Test;

public class IgnoreTestExample {
	
  @Test
  public void test1() {
	  System.out.println("This is test 1");
  }
  
  @Test(enabled=false)
  public void test2(){
	  System.out.println("This is test 2 ignore case");
  }
}

Console Output

In this console output, you see test2() didn’t get invoked and only test1() got executed.Ignore tests TestNG Console

Join our Facebook community to get the latest updates on Selenium WebDriver.

Join Inviul fb group

Leave a Reply