通过eclipse运行JUnit测试时,Maven surefire参数 [英] Maven surefire arguments when running JUnit test via eclipse

查看:126
本文介绍了通过eclipse运行JUnit测试时,Maven surefire参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven的新手问题 - Surefire - Eclipse - JUnit

A newbie question on Maven - Surefire - Eclipse - JUnit

我已将我的项目的pom文件中的maven-surefire-plugin配置为传递一些额外的JVM参数如下:

I have configured the maven-surefire-plugin in the pom file of my project to pass some additional JVM arguments as below:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven.surefire.plugin.version}</version>
            <configuration>
                <argLine>-d64 -Xms128m -Xmx4096m -XX:PermSize=512m -Duser.timezone=UTC -XX:-UseSplitVerifier</argLine>
            </configuration>
        </plugin>

当我从Eclipse运行这个项目的测试案例为Run As-> JUnit Test时,类路径被正确设置,argLine中指定的附加参数不包括在调用中。我必须去手动键入相关的 Debug Configurations 下的参数。我不太明白JUnit如何知道它需要将测试范围的jar放在类路径上,而在某种程度上意味着Eclipse中的JUnit工具通过M2E了解Maven?如果是这样,我们如何使它也读取argLine。我知道这听起来很具体 - 但是在类似情况下,其他人如何管理?

When I run a test case of this project from Eclipse as Run As->JUnit Test, though the classpath is correctly set, the additional arguments specified in the argLine are not included in the invocation. I have to go and manually key in the arguments under the relevant Debug Configurations. I don't quite understand how JUnit is aware that it needs to put jars of the test scope on the classpath and in some way means that JUnit tool in Eclipse is aware of Maven via M2E? If so, how can we make it also read argLine. I know this sounds very specific - but how do others manage in similar situations?

提前感谢

推荐答案

Eclipse JUnit启动器(选择运行方式 - > JUnit测试)是一个独立的测试运行器,具有自己的预定义构建和运行生命周期,与Maven毫无关系,它不会神奇地拾起你的pom,读取surefire配置并使用它们来驱动测试运行。

Eclipse JUnit Launcher (choose Run As -> JUnit Test) is a independent test runner which has its own pre-defined build and running life cycle and has nothing to do with Maven, it will not pick up your pom magically and read in the surefire configuration and use them to drive the test running.

如果您的项目作为现有的Maven项目导入,使用Maven(选择运行为 - > Maven测试)启动您的JUnit测试,该测试将拾取并使用surefire配置。这与从命令行运行 mvn test 完全相同,它只能在控制台中输出运行日志,您将无法使用漂亮的红色&绿色JUnit UI窗口。

If your project is imported as an existing Maven project, use Maven (choose Run as -> Maven test) launch your JUnit test which will pick up and use the surefire configuration. This is exactly same as running mvn test from commandline, it only output run log in console and you will not able to use the nice red & green JUnit UI window.

希望这是有道理的。

这篇关于通过eclipse运行JUnit测试时,Maven surefire参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆