Dave
Dave

Reputation: 19150

How do I make running a JUnit test in eclipse behave the same as running the Maven test on the command line?

I'm using Eclipse Oxygen for Java developers on Mac OS. I have imported my Maven projects into the IDE. Normally, at the command line, when I run a test, I'll run something like

mvn test -Dtest=UserServiceTest

In addition to running the "test" goal, this will also execute some custom code I have in the "process-resources" and "test-compile" goals. However, when I run my test in the Eclipse IDE (by right clicking on the class name in the package explorer, selecting "Run" and then selecting "JUnit Test"), I notice these other goals aren't run.

Is there a way to globally set up my project so that when I run a JUnit test, it automatically behaves like typing the command above? I realize I could individually edit the run configuration for each test, but since I have hundreds, this would take a lot of work and I'd have to do it each time I crated a new test. It would be great if there were some global way to set up Eclipse to do ti for me.

Upvotes: 0

Views: 609

Answers (1)

howlger
howlger

Reputation: 34165

Currently, Eclipse has no such built-in workspace or project settings/preferences and I do not know any plug-in for the desired feature.

The so-called Launch Configuration Templates/Prototypes (see also Eclipse bug 41353) are currently being developed and are expected to be shipped with Eclipse Photon on June 27, 2018.

Consider changing your tests so that they can be run on a local machine without additional parameters, e. g. via @BeforeClass (JUnit 4) or @BeforeAll (JUnit 5).

No solution, but tips how to avoid a few mouse clicks in this context:

  • To open and to edit a launch configuration, press Ctrl and click or choose the Run button or a launch configuration menu item.
  • Use the Eclipse Runner plug-in.

Upvotes: 1

Related Questions