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 the Author

author image
mkyong
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

avatar
4 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
Mukesh otwanisup ora29babu arigsTestNG Tutorials | J2EE Web Development Tutorials Recent comment authors
newest oldest most voted
Mukesh otwani
Guest
Mukesh otwani

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
Guest
sup ora29

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
Guest
babu arigs

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

Mukesh otwani
Guest
Mukesh otwani
trackback
TestNG Tutorials | J2EE Web Development Tutorials

[…] Tutorial 3 – Ignore Test Ignore certain method for unit test. […]