You can do it by implementing your own Test Runner similar to the Suite runner.
This runner should extract the marker annotation class from the value of the @SuiteClasses
annotation (you should probably replace @SuiteClasses
with your own annotation). Take a look at the getAnnotatedClasses
method of the org.junit.runners.Suite
class.
After having the marker annotation class, you should scan the classpath for test classes marked with this annotation (use a library such as Reflections) and pass an array of them to the appropriate Runner constructor.
You can find a similar behavior in the Suite
constructor:
public Suite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
this(builder, klass, getAnnotatedClasses(klass));
}