I am trying to pass a list of classes as a parameter. (Can I do this?) I am using JUnit and Selenium, I have JUnit test classes that are called by a JUnit test suite class, using @SuiteClasses()
and that test suite class is called by a class containing a main()
. My idea is to allow the user to pick JUnit classes from the main class which will be stored in some kind of list. The Test Suite that calls the JUnit test classes to be run will use that list and call those JUnit classes.
Original Code: the test suite class that calls the JUnit test classes that should be run (works) ⬇
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ TestCase1.class, TestCase2.class})
public class AllTests {
}
I am trying to change it to something like ⬇
@SuiteClasses(runnerClass.classesToTest)
and in the runner class I would have something like this. I was thinking, I can pull names of classes from prop file maybe, and allow the user to pick which classes will be added to variable classesToTest
⬇
public class runnerClass {
public static Class<?>[] classesToTest = { testCase1.class, testCase2.class };
public static void main(String[] args) {
...
}
}
When I try to do something like this, I get this error ⬇
The value for annotation attribute Suite.SuiteClasses.value must be a class literal
So question being, can I make this work? Am I creating my classesToTest
variable incorrectly?