Ignore Tests in TestNG



Ignore Tests in TestNG

In TestNG, we can ignore / skip test’s based on your requirement. 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.

@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 “@Test(enabled=false)”

And We can Skip a test by using TestNG Skip Exception if we want to Skip a particular Test.

Syntax:

throw new SkipException(“message”);

And we can also perform a CONDITIONAL 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.

Please find the below sample program.

package DemoPackage;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class clsLogin
{
@Test(enabled=true)   //This test case is enabled
public void VerifyLogin()
{
System.out.println(“I am verifying login form clsLogin”);
}
@Test(enabled=true)   //This test case wont be skipped
public void VerifyHomepage()
{
System.out.println(“I am verifying Homepage form clsLogin”);
}

@Test
public void SkipTest()  //This test case will be skipped
{
String condition =“Skip Test”;
if(condition.equals(“Skip Test”))
{
     throw new SkipException(“Skipping – This is not ready for testing “);
}
else
{
    System.out.println(“I am in else condition”);
}
System.out.println(“I am out of the if else condition”);
}

@Test(enabled=false)        //This test case will be ignored
@Parameters({“policyNumber”,”policyType”})
public void VerifyPolicyDetails(String policyNumber, String policyType) throws Exception
{
System.out.println(“Policy Number is:” + policyNumber );
System.out.println(“Policy Type is:” + policyType );
}

}

 

Tags: ,
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!

https://bridgejunks.com/ https://crownmakesense.com/ https://brithaniabookjudges.com/ https://hughesroyality.com/ https://rhythmholic.com/ https://bandar89.simnasfikpunhas.com/ https://www.100calshop.co.il/products/thailand/ https://myasociados.com/ https://solyser.com/ http://konfidence.cz/ https://muscadinepdx.com/ https://bandar89.parajesandinos.com.ve/ https://goremekoop.com/ https://oncoswisscenter.com/ https://www.turunclifehotel.com/bandar89/ https://www.houseofproducts.biz/ https://taimoormphotography.com/
BIJI18 BIJI18 BIJI18