user166566
user166566

Reputation:

Change default "Program to Run" in Eclipse launch configuration

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

Answers (4)

Stephan Herrmann
Stephan Herrmann

Reputation: 8178

This answer is a near miss:

Try this:

  1. Manually create and configure one "good" launch configuration.

Next time you want to launch a test that doesn't yet have a good launch configuration:

  1. Select the file and invoke Run As > Run Configurations ... (i.e., don't yet select JUnit Plug-in Test!)
  2. In that dialog select a good launch configuration of the same kind, and ...
  3. Then click New Launch Configuration (upper-left corner)

Now the newly created configuration should "inherit" the configured values from the the good configuration.

Truth is:

  • You can duplicate an existing launch configuration (leaving you to manually select the test to launch)
  • The Debug team once had plans to support launch configuration templates.

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

Stephan Herrmann
Stephan Herrmann

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.

  • Without that dependency [No Application - Headless Mode] is selected by default for newly created launch configurations.
  • With that dependency the default is Run a product, with s.t. like org.eclipse.platform.ide preselected.

Upvotes: 1

user166566
user166566

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:

  1. Add a custom BlaBlaPluginJUnitMainTab extends PluginJUnitMainTab
  2. Create a custom JUnitProgramBlock implementation (BlaBlaJUnitProgramBlock)
  3. Creating an instance of BlaBlaJUnitProgramBlock in the BlaBlaJUnitPluginTestTabGroup.BlaBlaPluginJUnitMainTab.createProgramBlock() method
  4. Overriding setDefaults-method (not sure if its really neccessary) in BlaBlaJUnitProgramBlock
  5. Overriding initializeForm-method in the BlaBlaJUnitProgramBlock and adjust parameter there too.

Leading to the following result:

enter image description here

Upvotes: 6

Saurabh
Saurabh

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. enter image description here

Upvotes: 4

Related Questions