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.

4 comments on “TestNG – How to ignore a test method

  1. 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

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *