HOME
In the previous tutorial, we have discussed about prioritizing the Test Cases using TestNG. In this tutorial, we will see how we can disable the Test Cases using TestNG.
Imagine there are 100 test cases in Regression Test Suite. We need to execute 99 test cases in a release and want not to execute any particular test case. But we do not want to delete that test case from the Test Suite also. In this case, TestNG has a feature which allows to skip a particular test case by setting the parameters to
@Test(enabled = false)
To use two or more parameters in a single annotation, separate them with a comma:
@Test(priority = 3, enabled = false)
To Run the TestNG program, right click on the program, select Run As TestNG Test

Below is an example to implement the above mentioned scenario
import org.testng.annotations.Test;
public class TestNGDisableDemo {
@Test(priority = 3)
public static void FirstTest() {
System.out.println("This is Test Case 1, but after priority Test Case 3");
}
@Test(priority = 4)
public static void SecondTest() {
System.out.println("This is Test Case 2, but after priority Test Case 4");
}
@Test(enabled = false)
public static void ThirdTest() {
System.out.println("This is Test Case 3, but now skipped");
}
@Test(priority = 1)
public static void FourthTest() {
System.out.println("This is Test Case 4, but after priority Test Case 1");
}
}
Output
This is Test Case 4, but after priority Test Case 1
This is Test Case 1, but after priority Test Case 3
This is Test Case 2, but after priority Test Case 4
PASSED: FourthTest
PASSED: FirstTest
PASSED: SecondTest
===============================================
Default test
Tests run: 3, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 3, Passes: 3, Failures: 0, Skips: 0
===============================================

Nice blog. Can you explain how to perform dependency between two test case with the help of TestNG.
LikeLike
Thanks John. There is a new tutorial on the same topic.https://configureselenium.blogspot.com/2020/02/how-to-create-dependency-between.htmlPlease have a look
LikeLike