During some instance you wish not to run certain test but you might have to run them later, to do the people usually comment line using multi-line comment. In TestNG we can do this by simply passing false in the enable parameter of test annotation.
Syntax
@Test(enabled = value)
e.g, @Test(enabled = false)
The value can only be either true or false, we no need to exclusively provide true as the default value is true while creating test annotation. To under stand this even more clearly we will show and explain the concept in the below code and its explanation.
Code
import org.testng.annotations.Test; public class Disabling_Class{ @Test() void Testone(){ System.out.println("This is Test 1"); } @Test(enabled = false) void Testtwo(){ System.out.println("This is Test 2"); } @Test() void Testthree(){ System.out.println("This is Test 3"); } }
Explanation
We have 3 test in the above class when executing the test, Testone and Testthree will only be executed as the enable in the test is set to false for Testtwo and we can also see that enable is not exclusively set to true for test Testone and Testthree
Result
With Test Disabled
Without Test Disabled
Source
Test_Disabled.java : https://drive.google.com/file/d/14TCJQm3aVej0SwYvy25X8HkJDm6HjW2V/view?usp=sharing
No_Disabled.java : https://drive.google.com/open?id=1kNWzJBpML0THIUmo0BwVUn0ghtct2rxw