I am trying to use JUnitCore.runClasses() and I can get it running using the following code
JUnitCore.runClasses(testClass.class);
But i was curious, as runClasses() can take any number of parameters, is it possible to use code similar to the following?
Class c = testClass.class;
JUnitCore.runClasses(c);
Or
List<Class> c = new ArrayList<>{test1.class, test2.class, test3.class};
JUnitCore.runClasses(c);
I am asking this as if you try to pass a java.io.File type to JUnitCore.runClasses() you get the following error
no suitable method found for runClasses(java.io.File)
method org.junit.runner.JUnitCore.runClasses(java.lang.Class<?>...) is not applicable
(argument type java.io.File does not conform to vararg element type java.lang.Class<?>)
method org.junit.runner.JUnitCore.runClasses(org.junit.runner.Computer,java.lang.Class<?>...) is not applicable
(actual argument java.io.File cannot be converted to org.junit.runner.Computer by method invocation conversion)
I assume you are trying to do the following:
You have a file containing a java class which you want to run using JUnitCore.
To acomplish this you will have to:
Code sample:
The example will only work if the class does not have a package. You can write an own class loader to control the class loading process. See the javadoc for URLClassLoader to learn how this class loader works. For writing a custom class loader you could consult this.