Enabling or Disabling a Test case in TestNG

To enable or disable a test case in testng, an attribute called enabled is passed which is a boolean attribute where when the value is:

true – test case will be executed.

false – test case will not be executed.

By Default, the value of this attribute is true.

Let us consider below example which has 4 test cases, we are passing enabled = false in testcase2 method.

package testNG;

import org.testng.annotations.Test;

public class TestNG {

	@Test (priority=2)
	public void testcase1(){
		System.out.println("Test case 1");
	}

	@Test (priority=1)
	public void testcase3(){
		System.out.println("Test case 3");
	}

	@Test (priority=4, enabled= false)
	public void testcase2(){
		System.out.println("Test case 2");
	}

	@Test (priority=3)
	public void testcase4(){
		System.out.println("Test case 4");
	}

}

Here, in above code, as testcase2 method is disabled. So it will not be executed and output will be:

Test case 3
Test case 1
Test case 4

PS: For any questions queries or comment feel free to write us at saurabh@qatechhub.com or support@qatechhub.com. Happy Learning 🙂

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: