You can make use of a Test Suite.
The test suite
@RunWith(Suite.class)
@Suite.SuiteClasses({ TestClass.class, Test2Class.class, })
public class TestSuite {
@BeforeClass
public static void setup() {
// the setup
}
}
and, the test classes
public class Test2Class {
@Test
public void test2() {
// some test
}
}
public class TestClass {
@Test
public void test() {
// some test
}
}
Or, you can have a base class which handles the setup
public class TestBase {
@BeforeClass
public static void setup() {
// setup
}
}
and, then the test classes can extend the base class
public class TestClass extends TestBase {
@Test
public void test() {
// some test
}
}
public class Test2Class extends TestBase {
@Test
public void test() {
// some test
}
}
However, this will call the setup
method in TestBase
for all its subclasses everytime each of them executes.