Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable entire unit test in TestNG?

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?

like image 324
yegor256 Avatar asked Jun 02 '11 00:06

yegor256


People also ask

Can we disable a test in TestNG?

In such cases, annotation @Test(enabled = false) helps to disable this test case. If a test method is annotated with @Test(enabled = false), then the test case that is not ready to test is bypassed. Now, let's see @Test(enabled = false) in action.

How do I ignore an entire test class?

If you want to ignore a test method, use @Ignore along with @Test annotation. If you want to ignore all the tests of class, use @Ignore annotation at the class level.


1 Answers

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.

like image 108
razlebe Avatar answered Sep 28 '22 06:09

razlebe