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.

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Mukesh otwani
9 years ago

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/

sup ora29
10 years ago

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

babu arigs
11 years ago

what if I want to disable a test based on condition?

Mukesh otwani
9 years ago
Reply to  babu arigs