Reputation:
every now and then I am launching JUnit tests from within Eclipse by using
Run As > JUnit Plug-in Test
By default Eclipse assumes you are running something which requires a workbench and chooses in the "Main" section of the launch configuration
LaunchConfig > Main > Program To Run > Run an application > org.eclipse.ui.ide.workbench
I can understand why this is the default, but for me (and for all in our team) this is never ever the case. We always need to run our JUnit Plug-in Tests as
LaunchConfig > Main > Program To Run > Run an application > [No Application] Headless Mode
How do I change this default behaviour? I am currently using Eclipse 4.4.
Upvotes: 9
Views: 3727
Reputation: 8178
This answer is a near miss:
Try this:
Next time you want to launch a test that doesn't yet have a good launch configuration:
Run As > Run Configurations ...
(i.e., don't yet select JUnit Plug-in Test
!)New Launch Configuration
(upper-left corner)Now the newly created configuration should "inherit" the configured values from the the good configuration.
Truth is:
Edit 2018:
Since Eclipse Photon, the Java debugger supports launch configuration prototypes. I just filed Bug 536728 to request this also for test launches. Feel free to chime in (or contribute) on that bug.
Upvotes: 6
Reputation: 8178
There seems to be a simple and effective heuristic in place, which decides whether or not a JUnit Plug-in Test should be run headlessly or with an application:
Make sure that the plug-in containing your tests has no dependencies on anything org.eclipse.ui
.
[No Application - Headless Mode]
is selected by default for newly created launch configurations.Run a product
, with s.t. like org.eclipse.platform.ide
preselected.Upvotes: 1
Reputation:
It seems a custom LaunchConfiguration-Extension is a viable solution attempt. What I did was to create a new, custom LaunchConfiguration-Extension which is 99.999% build on the JUnitLaunchConfiguration. I only had to add a custom
BlaBlaJUnitPluginTestLauncher extends launching.JUnitLaunchConfigurationDelegate
which overrides the
launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
method to adjust the application parameters according to our needs.
BlaBlaJUnitPluginTestTabGroup extends org.eclipse.pde.ui.launcher.JUnitTabGroup
To be able to initialize the LaunchConfig dialog with the default parameter, I had to:
BlaBlaPluginJUnitMainTab
extends PluginJUnitMainTab
BlaBlaJUnitProgramBlock
)BlaBlaJUnitProgramBlock
in the BlaBlaJUnitPluginTestTabGroup.BlaBlaPluginJUnitMainTab.createProgramBlock()
methodsetDefaults
-method (not sure if its really neccessary) in BlaBlaJUnitProgramBlock
BlaBlaJUnitProgramBlock
and adjust parameter there too.Leading to the following result:
Upvotes: 6
Reputation: 455
if u r looking for only shortcut for convenience then eclipse remembers last execution. After using run as and saving ur run config, just use "Run as" button in toolbar.
besides this eclipse comes with flavour for testers, u can check that out.
Also since you are talking about unit testing see if you can make use of ant build or even better converting to maven based project. Maven has integrated support for testing.
Upvotes: 4