问题描述
我在Mac OS上为Java开发人员使用Eclipse Oxygen.我已经将Maven项目导入到IDE中.通常,在命令行上,当我运行测试时,我会运行类似的
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
除了运行测试"目标外,这还将执行一些我在过程资源"和测试编译"目标中拥有的自定义代码.但是,当我在Eclipse IDE中运行测试时(通过右键单击包资源管理器中的类名称,选择运行",然后选择"JUnit测试"),我注意到这些其他目标并未运行.
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.
是否有一种全局设置项目的方法,以便在运行JUnit测试时,它的行为就像在键入上面的命令一样?我意识到我可以分别编辑每个测试的运行配置,但是由于我有数百个,这将需要很多工作,因此每次创建新测试时都必须这样做.如果有某种全局的方法可以设置Eclipse为我做ti,那就太好了.
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.
推荐答案
当前,Eclipse没有没有这样的内置工作区或项目设置/首选项,而我没有知道所需功能的任何插件.
Currently, Eclipse has no such built-in workspace or project settings/preferences and I do not know any plug-in for the desired feature.
所谓的 启动配置模板/原型 (另请参见 Eclipse错误41353 )目前正在开发中,预计将随.
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.
请考虑更改测试,以便可以在没有附加参数的情况下在本地计算机上运行测试,例如G.通过@BeforeClass
(JUnit 4)或@BeforeAll
(JUnit 5).
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:
- 要打开并编辑启动配置,请按 ,然后单击或选择 Run 按钮或启动配置菜单项.
- 使用 Eclipse Runner 插件.
- To open and to edit a launch configuration, press and click or choose the Run button or a launch configuration menu item.
- Use the Eclipse Runner plug-in.
这篇关于如何使在Eclipse中运行JUnit测试的行为与在命令行上运行Maven测试的行为相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!