63

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?

yegor256
  • 102,010
  • 123
  • 446
  • 597

1 Answers1

95

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.

razlebe
  • 7,134
  • 6
  • 42
  • 57
  • 11
    That's the correct answer: it will mark all the public methods of the class as disabled. Note that putting a @Test on a method will re-enable that method, and that method only. Let me know if you're seeing something different. – Cedric Beust Jun 02 '11 at 02:54
  • 1
    Apparently, others have also had issues with @Test when applied at class level. See [this question](http://stackoverflow.com/questions/1149147/does-testenabled-false-work-for-a-class-in-testng). – razlebe Jun 02 '11 at 06:27
  • Perhaps it's a bug in some versions of TestNG. – razlebe Jun 02 '11 at 06:28
  • 2
    Confirmed: it *is* a bug, according to [this Google cache of the OpenSymphony bug page](http://jira.opensymphony.com/browse/TESTNG-434) that was tracking it. – razlebe Jun 02 '11 at 08:55
  • 1
    The nice thing about the JUnit @Ignore is that you can specify the reason why you are ignoring the test. Is there any way to do this in TestNG other than leaving a comment that someone might forget to delete when they re-enable the test? – Jun-Dai Bates-Kobashigawa Mar 12 '13 at 12:43
  • Yeah, I had the same problem adding it to the class level. I had to place the enabled=false in ALL tests. – Marcello DeSales Aug 15 '13 at 20:40