[英]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. 我正在Mac OS上为Java开发人员使用Eclipse Oxygen。 I have imported my Maven projects into the IDE.
我已经将我的Maven项目导入了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.
但是,当我在Eclipse IDE中运行测试时(通过右键单击包浏览器中的类名称,选择“运行”,然后选择“ JUnit测试”),我注意到这些其他目标并未运行。
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? 有没有一种方法可以全局设置项目,以便在我运行JUnit测试时,它的行为就像在键入上面的命令一样? 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 没有此类内置工作区或项目设置/首选项,并且我不知道所需功能的任何插件。
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 . 当前正在开发所谓的启动配置模板/原型 (另请参阅Eclipse bug 41353 ),并有望在2018年6月27日与Eclipse Photon一起交付。
Consider changing your tests so that they can be run on a local machine without additional parameters , eg via @BeforeClass
(JUnit 4) or @BeforeAll
(JUnit 5). 考虑更改测试,以便它们可以在没有附加参数的情况下在本地计算机上运行,例如通过
@BeforeClass
(JUnit 4)或@BeforeAll
(JUnit 5)。
No solution, but tips how to avoid a few mouse clicks in this context: 没有解决方案,但是提示了如何在这种情况下避免几次鼠标单击:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.