Main Tutorials

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.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Mukesh otwani
7 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
8 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
9 years ago

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

Mukesh otwani
7 years ago
Reply to  babu arigs