TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • TestNG
  • Tools
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

TestNG

Enable and Disable Test in TestNG

Introduction

To enable or disable a test we can use the enabled attribute. To enable a test we can use the flag “enabled=true”.  We can disable the test in TestNG by using the attribute “enabled=false” for the @Test method. We will see how to disable a test with a code example.

Disable a Test

public class TestNGDisableTest {

@Test(enabled=false) 
 public void disabledMethod() 
 { 
 System.out.println("In disabledMethod.. This never runs..!");
 }

}

 

Note that for the enabled method the attribute switch (enabled=true) is by default. So you may skip the switch for enabled method.

One of the most common error that is usually made is adding a dependency on a disabled test. In the next section, we will see what happens when we add the dependency on a disabled test.

 

import org.testng.annotations.Test;

public class TestNGDisableTest {
 
@Test(enabled=false)
public void disabledMethod()
{ 
 System.out.println("In disabledMethod"); 
} 
 
 
@Test(dependsOnMethods={"disabledMethod"}) 
public void dependentMethod()
{ 
 System.out.println("In dependentMethod"); 
 
}

}

 

If we run the above test class we would get exception as below.

org.testng.TestNGException:
com.testingdocs.testng.sample.TestNGDisableTest.dependentMethod() is depending on method public void com.testingdocs.testng.sample.TestNGDisableTest.disabledMethod(), which is not annotated with @Test or not included.

 

TestNG Tutorials on this website can be found at:

https://www.testingdocs.com/testng-framework-tutorial/

For more details on the TestNG Framework, visit the official website of TestNG at:

https://testng.org

Related Posts

Tests TestNG Suite testng.xml

TestNG /

Run tests from TestNG Suite testng.xml file

Add TestNG library

TestNG /

Add the TestNG library to the project

new TestNG class

TestNG /

Create TestNG test class in Eclipse IDE.

TestNG Plugin IntelliJ

TestNG /

Enable TestNG in IntelliJ IDE

Installing Eclipse from Update Site

TestNG /

Install TestNG latest version from the update site

‹ Exception Test TestNG Example› TestNG @Test Annotation Attributes -2

Recent Posts

  • Antivirus Products for Windows 11 PC
  • Install CodeBlocks IDE on Windows 11
  • Location Privacy Settings on Windows
  • Windows 11 Virus & Threat Protection
  • Download & Install Python on Windows 11
  • Cumulative Update for Windows 11 Version
  • Test execution speed in Selenium IDE
  • Check Windows 11 Free Upgrade
  • Download IntelliJ IDE on Windows 11
  • New MySQL Connection in Workbench

Back to Top

Automation Tutorials

  • JBehave Tutorial
  • Selenium Tutorial
  • TestNG Tutorial
  • JUnit Tutorial

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version