I am developing for Eclipse, and one feature is run JUnit tests. Now my plugin detect JUnit tests on a project in workspace and after this I want to call JUnit to run this tests.
I heard about ILaunch, ILaunchConfigurationDelegate, JUnitLaunchConfigurationDelegate but I cannot found an example of this and also I’m not sure if I have to use this!
— Thanks in advance
Please see my answer to How does Eclipse actually run Junit tests?. You will need to create a Run Configuration and then call JUnitLaunchConfigurationDelegate#launch() with the configuration.
The easiest way to do this is to add shortcuts to the extension point
org.eclipse.debug.ui.launchShortcuts. With the correct configurationType, you can create the correct type and normally, Eclipse will do the rest. In fact this is exactly what we’ve done in the Scala IDE.Here is the relevant XML from scala-ide:
The important element is the <contextualLaunch>, which defines a set of tests which need to be true in order that the option to launch as JUnit be presented to the user. Most of these are self explanatory, but we’ve also
scala.tools.eclipse.launching.canLaunchAsJUnit, which references an extension pointorg.eclipse.core.expressions.propertyTesters. These property testers test whether the code can be launched as JUnit or not (for instance, the class under test extends TestCase or whatever).If you need more details, I recommend downloading Scala IDE, and looking at the code, but it is written in Scala.