Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Test Suite to Ignore

I have many Test Suites with each one contains many Test Classes. Here is how they look like:

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses( {ATest.class, BTest.class})
public class MyFirstTestSuite {

    @BeforeClass
    public static void beforeClass() throws Exception {
                // load resources
    }

    @AfterClass
    public static void afterClass() throws Exception {
        // release resources

    }
}

Sometimes I want to disable a whole Test Suite completely. I don't want to set each test class as @Ignore, since every test suite loads and releases resources using @BeforeClass and @AfterClass and I want to skip this loading/releasing when the test suite is ignored.

So the question is: is there anything similar to @Ignore that I can use on a whole Test Suite?

like image 444
adranale Avatar asked Jun 12 '12 08:06

adranale


People also ask

How do you ignore test cases in testing?

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 you ignore a 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.

How do I ignore a method in JUnit?

Annotation Type Ignore. Sometimes you want to temporarily disable a test or a group of tests. Methods annotated with Test that are also annotated with @Ignore will not be executed as tests. Also, you can annotate a class containing test methods with @Ignore and none of the containing tests will be executed.


1 Answers

You can annotate the TestSuite with @Ignore.

@RunWith(Suite.class)
@SuiteClasses({Test1.class})
@Ignore
public class MySuite {
    public MySuite() {
        System.out.println("Hello world");
    }

    @BeforeClass
    public static void hello() {
        System.out.println("beforeClass");
    }
}

doesn't produce any output.

like image 54
Matthew Farwell Avatar answered Oct 22 '22 03:10

Matthew Farwell