TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • 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

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version