I'm trying to find a way to run 1 (later even more) JUnit-tests from a plugin.
At the moment, the only way I have found seems to be very cumbersome and does not quite look right:
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType launchConfig = launchManager.getLaunchConfigurationType("org.eclipse.jdt.junit.launchconfig");
ILaunchConfigurationWorkingCopy workingCopy = launchConfig.newInstance(null, "name");
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "javaprojectname");
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "testclassname");
workingCopy.setAttribute("org.eclipse.jdt.junit.TEST_KIND", "org.eclipse.jdt.junit.loader.junit4");
ILaunchConfiguration config = workingCopy.doSave();
config.launch(ILaunchManager.RUN_MODE, null);
As you can see, I'm setting a lot of attributes with magic strings. Is there a better way to achieve this ?