版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://ralf0131.blogbus.com/logs/75672327.html
参考:
http://blog.tfd.co.uk/2007/09/05/surefire-unit-test-arguments-in-maven-2/
http://maven.apache.org/plugins/maven-surefire-plugin/howto.html
http://mavenize.blogspot.com/2007/07/setting-command-line-arguments-for.html
都说Maven2是Ant的替代品,今天稍微使用了下Maven,记录备忘。
通过Maven单独运行一个Junit测试用例(无需配置surefire):
mvn -Dtest=TestXXX test
为Maven运行添加JVM参数,比如想给运行Maven的JVM分配更多内存,或者进行profiling等。有两种方法,一种是全局方法,即设置一个全局的环境变量MAVEN_OPTS。
linux下可修改.profile或者.bash_profile文件:export MAVEN_OPTS=-Xmx1024m
windows下可以添加环境变量MAVEN_OPTS
这样对于所有的maven进程都会启用这个JVM参数,所以是一个全局变量,具体可在bin\mvn.bat或者mvn.sh文件中找到如下内容:(%MAVEN_OPTS%即为全局JVM参数)
@REM Start MAVEN2
:runm2
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" org.codehaus.classworlds.Launcher %MAVEN_CMD_LINE_ARGS%
如果有更加specific的需求,比如要单独运行一个JUnit Testcase,并且要fork出一个新的JVM来运行,还要为这个JVM加上特定的参数,那就需要更改项目的pom.xml文件了。具体方法是,修改项目的pom.xml在<build>-><plugins>,添加一个plugin,目的是配置surefire,使得每运行一个testcase,都单独fork出一个新的JVM来运行,若还要添加JVM参数,则可通过maven.test.jvmargs来进行传递:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>pertest</forkMode>
<argLine>${maven.test.jvmargs}</argLine>
</configuration>
</plugin>
然后在<properties>标签下加入,这样maven能够知道maven.test.jvmargs这个参数存在,默认值为空,通过运行时命令行传入:
<deploy.target/>
<maven.test.jvmargs></maven.test.jvmargs>
最后通过如下命令来运行,其中-Dtest是需要运行的testcase的名称,-Dmaven.test.jvmargs指需要传入的JVM参数,maven将这个参数传给新的fork出来的JVM运行。
mvn -Dtest=TestXXX -Dmaven.test.jvmargs='-agentlib:xxxagent -Xmx128m' test
分享到:
相关推荐
<dependency> <groupId>gui.ava</groupId> <artifactId>html2image</artifactId> ...maven 下载到 maven库下边的gui.ava.html2image0.9 及jar 可以直接使用,在 一些依赖库中下载不下来,所以放到这里方便使用
在build-plugins添加本plugin <build> <plugins> <plugin> <groupId>org.nutz.boot</groupId> <artifactId>nutzboot-maven-plugin</artifactId> <version>${nutzboot.version}</version> </plugin> </...
主要介绍了如何在Maven项目中运行JUnit5测试用例实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Java基于POI的导入导出excel功能,附带测试功能,项目基于Maven,导入即可用,带测试Main方法提供例子。 用于导入导出Excel的Util包,基于Java的POI。可将List<Bean>导出成Excel,或读取Excel成List<Bean>、Map...
2.修改maven中conf/setting.xml的配置修改仓库位置、以及 配置server 如 <localRepository>D:\Program Files\apache-maven-3.3.3\repository</localRepository> <server> <id>tomcat7</id> <username>admin</...
<artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins...
-- 为了方便进行单元测试,添加spring-test包 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.2.1.RELEASE</version> </dependency> <!...
<groupId>org.apache.axis2</groupId> <artifactId>axis2</artifactId> <version>1.6.2</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-...
该资源为SpringMVC中json转换所需要的Maven仓库,如果maven下载包的时候速度太慢,可以使用我的这个资源,把这个直接考到本地Maven仓库即可。 对应的Maven依赖如下: <dependency> <groupId>org.codehaus.jackson</...
根据maven阿里云仓库推荐配置,弄的一个比较快的maven源配置 <mirrors> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>...
在web应用程序中,添加以下JAR包到/web-inf/lib目录: - taglibs-standard-spec-1.2.5.jar - taglibs-standard-impl-1.2.5.jar - taglibs-standard-jstlel-1.2.5.jar - xalan-2.7.1.jar - serializer-2.7.1.jar...
<artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> 添加...
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </...
1、先在pom.xml文件中加入<build></build>标签 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.1</version> ...
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <version>3.1</version> <failOnMissingWebXml>false</failOnMissingWebXml...
在网上搜索一堆文章没找到解决方法,只找到了tomcat7-maven-plugin的...并没有找到tomcat8-maven-plugin的plugin,在Maven的中央仓库中根本就没有这个插件: https://repository.apache.org/content/repositories/snaps
1. mvn-examples-1.0 <modules> <module>ch03-simple</module> <module>ch04-custom</module> <module>ch05-simple-web</module> <module>ch06-multi</module> <module>ch07-multi-spring...2.Maven权威指南中文版
在<build>里面添加 <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>7.0.0.pre5</version> </plugin> </...
用法添加 maven 依赖项(尚未在 Maven Central 上!): <dependency><groupId>com.github.neothemachine</groupId><artifactId>gwt-webdriver-junit-runstyle</artifactId><version>0.0.1-SNAPSHOT</version><scope...
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=... <name>SeleniumJava Maven Webapp</name> <url>http://maven.apache.org</url>