Junit4 - You can try using
@Ignore
public class IgnoreMe {
@Test public void test1() { ... }
@Test public void test2() { ... }
}
transformed to something like -
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@SuiteClasses( {IgnoreMe.class, AnotherIgnored.class})
@Ignore
public class MyTestSuiteClass {
....
// include BeforeClass, AfterClass etc here
}
Source - Ignore in Junit4
Junit5 - You can try something similar like -
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@Disabled
class DisabledClassDemo {
@Test
void testWillBeSkipped() {
}
}
Source - Disabling Tests in Junit5
along with suite implementation in Junit5 as
If you have multiple test classes you can create a test suite as can
be seen in the following example.
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.runner.SelectPackages;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
@SelectPackages("example")
@Disabled
public class JUnit4SuiteDemo {
}
The JUnit4SuiteDemo will discover and run all tests in the example
package and its subpackages. By default, it will only include test
classes whose names match the pattern ^.*Tests?$.
where @SelectPackages
specifies the names of packages to select when running a test suite via @RunWith(JUnitPlatform.class)
, so you can specify those which you want to execute OR those which you don't want to execute and mark them disabled as above.
Further reads - @Select in Junit5 and Running a Test Suite in Junit5