in my project i want run methods(with annotation @Test) in classes in src/test/java that are contained in a jar (this jar contain also test classes). My code for run test method is this:
public class ServiceUtil {
Launcher launcher = LauncherFactory.create();
ClassLoader loader = URLClassLoader.newInstance(
new URL[]{new File("C:\\User\\Giuseppe\\test_path"+ "\\" + jar).toURI().toURL()}, //in Unix usare "/"
ServiceUtil.class.getClassLoader()
);
Class cls = loader.loadClass("MyTestClass");
Constructor constructor = cls.getConstructor();
Object o = constructor.newInstance();
LauncherDiscoveryRequest request;
if (o!=null) {
cls=o.getClass();
Method m=o.getClass().getMethod("MyMethodTest".get());
request = LauncherDiscoveryRequestBuilder.request()
.selectors(selectMethod(cls, m))
.build();
}
TestPlan testPlan = launcher.discover(request);
LOGGER.info("containTest? "+testPlan.containsTests()+""); <----IS FALSE!!!!
launcher.registerTestExecutionListeners(listener);
launcher.execute(request);
}
Tests are not executed because no valid test methods are detected (infact testPlan.containsTests() is False) but i dont view ERROR!
Some tips for this "stange error?"
Is possible execute JUNIT5 Test from external?
Thanks Regards
Aucun commentaire:
Enregistrer un commentaire