How to Skip Exception Test in TestNG

click here for more How to Skip Exception Test in TestNG

Using TestNG, we have multiple ways to Skip a test based on our requirement. We can Skip complete test without executing it or we can Skip a test when a specific condition is not satisfied.

read more Case 1: In TestNG,  visit @Test(enabled=false) annotation is used to skip a test case if it is not ready to test. We don’t need to import any additional statements.

As in JUnit, TestNG will not show you the other test method as Skipped or Ignored. It will not consider that case method at all when the annotation is mentioned as “ check it out @Test(enabled=false)”. Case 2: And We can Skip a test by using TestNG Skip Exception if we want to Skip a particular Test.
Syntax: next page throw new SkipException(“message”);

dallas arbiter fuzz face dating Case 3: we can also perform a CONDITIONAL try here Skip, i.e. we can have a condition to check and then SKIP test if condition is not satisfied. For Example, if there is no data available to perform a test, we can skip the test instead of making that test as failed.

Let us see all the above three cases by taking three simple tests.

Please find the below sample program.

package TestNGPack2;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.SkipException;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class SkipExample {
public static WebDriver driver = new FirefoxDriver();
String DataAvailable="null";
    public void setup() throws Exception { 
         driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  public void TC001(){
      System.out.println("TC001  Executed");
  public void TC002(){
      System.out.println("I am in TC002 - Intensional Skip");
      String title = driver.getTitle();
      if(title.equals("Welcome: Mercury tours"))
                //To Skip Test
        throw new SkipException("TC002 Is Skipped");
      System.out.println("TC002 Executed Successfully");

  public void TC003(){
    System.out.println("Im in Conditional Skip");
          throw new SkipException("TC003 is Skipped - Data Not Available");
    System.out.println("TC003 Executed Successfully");
    public void tearDown() throws Exception { 


Once executed the above program the output will look as below.

As you see the above output, TC001() method is not executed at all. Because It will not consider that case method at all when the annotation is mentioned as @Test(enabled=false)

TC002() method is Executed and passed. Because The Page Title is matched, so it did not go inside if condition. It will skip if the Title will not match with Expected.

TC003() is Skipped. Test TC003 will be skipped only when data is not available. Here I took a simple variable DataAvailable for ease of understanding. The ‘if condition satisfied, hence Skipped the test. You can put condition according your requirement.