Show List
JUnit test suites
A JUnit test suite is a collection of test classes that are combined and executed together. Test suites provide a way to group related tests and run them as a single unit. There are two ways to create test suites in JUnit: using annotations or using a suite class.
- Annotation-based test suite:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestClassA.class,
TestClassB.class,
TestClassC.class
})
public class TestSuiteExample {
// the class remains empty, used only as a holder for the above annotations
}
- Suite class:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
public class TestSuiteExample {
public static void main(String[] args) {
org.junit.runner.JUnitCore.runClasses(
TestClassA.class,
TestClassB.class,
TestClassC.class
);
}
}
In both cases, when the test suite is executed, all the tests in the test classes
TestClassA
, TestClassB
, and TestClassC
will be run.Leave a Comment