I have a test suite class:
@RunWith(Suite.class)
@Suite.SuiteClasses({
GameMasterTest.class,
PlayerTest.class,
})
public class BananaTestSuite {
Make a super test class containing the method annotated with @BeforeClass. Extend all the test classes from this class, eg,
@Ignore
public class BaseTest {
@BeforeClass
public static void setUpBaseClass() {
//Do the necessary setup here
}
}
This method will run before any @BeforeClass annotated method in the subclasses: Source. Ensure that this method name is not used in any subclass to prevent shadowing.
If you need to run this just once (eg, if you are creating/initializing a large resource for all tests to use), set a flag in the super class to check whether the method ran or not.
This design will also ensure that if you change the test runner, you need not change anything else.