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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With