TestNG Ignore or Disable Tests

Filed Under: TestNG

Sometimes we want to ignore a TestNG test method, there are many ways to achieve this.

TestNG @Test enable parameter

We can disable or ignore a test method by adding enabled=false to @Test annotation. Let’s look at a simple example of ignoring a test method using this.

package com.journaldev.utils;

import org.testng.annotations.Test;

public class TestNGExample {

	public void foo() {
		System.out.println("Running foo test");
	public void bar() {
		System.out.println("Running bar test");
	public void zoo() {
		System.out.println("Running zoo test");
	public void base() {
		System.out.println("Running base test");

When above test class is executed, we get following output confirming that bar() method didn’t get executed.

[RemoteTestNG] detected TestNG version 6.14.3
Running base test
Running foo test
Running zoo test
PASSED: base

This method has a huge demerit, every time we want to disable a method we need to do code change and compile our classes again.

TestNG Disable Tests in XML Suite

TestNG XML suite files provide a lot of options. We can exclude test methods as well as groups from the execution. Let’s create a simple TestNG XML suite file where we will exclude foo method. We will also exclude zoo from the test execution.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="TestNG Excludes Test Suite" guice-stage="DEVELOPMENT">
			<exclude name="zoo"></exclude>
	<test thread-count="5" name="TestNG Excludes Test" verbose="2">
				<exclude name="zoo"></exclude>
			<class name="com.journaldev.utils.TestNGExample">
					<exclude name="foo"></exclude>

Run above XML file as TestNG Suite and it will produce following output.

TestNG Disable test method xml suite

Notice that we can exclude groups from execution at suite level as well as test level. Above XML code is showing both ways, however, in this case, it’s redundant and we can remove any one of those configurations.

You can download the example code from our GitHub Repository.
Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors