TestNG – How to ignore a test method
In this tutorial, we will show you how to ignore a test method with @Test(enabled = false)
.
TestIgnore.java
package com.mkyong.testng.examples.ignore;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestIgnore {
@Test //default enable=true
public void test1() {
Assert.assertEquals(true, true);
}
@Test(enabled = true)
public void test2() {
Assert.assertEquals(true, true);
}
@Test(enabled = false)
public void test3() {
Assert.assertEquals(true, true);
}
}
Output
[TestNG] Running:
PASSED: test1
PASSED: test2
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
In the above example, the test3 ()
test method is ignored.
Hi MkYong,
We have one more way using SkipException in TestNg where we can skip the test based on some scenario http://learn-automation.com/testng-tutorials-for-beginners/
Hi ,
I have a scenario where my testcase is enabled = false but it dependsOnGroups/methods = “YYY”
When I execute the methods I notice that this test case(enabled = false) is not executed but the methods it is dependant on is executing..
Can you let me know a way / a property/a tag where n the method and its dependant method both are not executed
what if I want to disable a test based on condition?
You can use SkipException of TestNG http://learn-automation.com/testng-tutorials-for-beginners/