How to disable entire unit test in TestNG?

JavaUnit TestingJunitTestng

Java Problem Overview


This is what I can do in JUnit:

import org.junit.*;
@Ignore
public class FooTest {
  //
}

and the entire class will be ignored. How can I do the same in TestNG?

Java Solutions


Solution 1 - Java

I believe what you want is:

@Test(enabled=false)
public class FooTest {
  //
}

(You can apply the @Test annotation to the class, as well as to methods individually.)

The TestNG documentation has a comprehensive list of the supported annotations, and also describes exclusion/inclusion of tests by group if that's of any interest. Here's a quote from the relevant section:

> @Test Marks a class or a method as > part of the test. > > ...(snip)... > > enabled: Whether methods on this class/method are enabled.

EDIT: Ignoring a class by applying @Test(enabled=false) is apparently buggy functionality in some versions of TestNG according to this defect that was raised against TestNG.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionyegor256View Question on Stackoverflow
Solution 1 - JavarazlebeView Answer on Stackoverflow