samedi 8 octobre 2016

Run JUnit test programmatically loading different .class files

i'm currently able to run a JUnit test programmatically doing something like this:

JUnitCore junit = new JUnitCore();
Result result = new Result();

File root = new File("rootWhereSommatoreTest.classIS");
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[]{root.toURI().toURL() });
Class<?> cls = classLoader.loadClass("SommatoreTest");  
result = junit.run(cls);
return result;

What i dislike about this code is that SommatoreTest.class must be in the same directory as Sommatore.class to work. So i was wondering if it was possible to run a Junit test, loading separately .class files from different directories in the same ClassLoader, enabling SommatoreTest to "see" Sommatore.

Thanks in advance for your answer! And keep up the good work!





Aucun commentaire:

Enregistrer un commentaire