Search code examples
javajunitjunit4test-suite

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?


Solution

  • 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.