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

﹥>﹥吖頭↗ 提交于 2019-12-11 15:11:38

问题


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.


回答1:


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.


来源:https://stackoverflow.com/questions/47360256/how-do-i-make-running-a-junit-test-in-eclipse-behave-the-same-as-running-the-mav

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!