首页 > 其他 > 详细

maven中跳过单元测试

时间:2014-03-01 09:32:44      阅读:539      评论:0      收藏:0      [点我收藏+]

Maven 提供了跳过单元测试的能力,只需要使用 Surefire 插件的 skip 参数。 在命令行,只要简单的给任何目标添加 maven.test.skip 属性就能跳过测试:

 

$ mvn install -Dmaven.test.skip=true
...
[INFO] [compiler:testCompile]
[INFO] Not compiling test sources
[INFO] [surefire:test]
[INFO] Tests are skipped.
...

当 Surefire 插件到达 test 目标的时候,如果 maven.test.skip 设置为 true ,它就会跳过单元测试。 另一种配置 Maven 跳过单元测试的方法是给你项目的 pom.xml 添加这个配置。 你需要为你的 build 添加 plugin 元素。

<project>
[...]
<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
</build>
[...]
</project>

 

当需要单元测试时,注意,一定要设置为false。

 

 配置生产和测试环境两种:

<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<filter.property.path>src/main/resources/properties/test.properties</filter.property.path>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<filter.property.path>src/main/resources/properties/production.properties</filter.property.path>
</properties>
</profile>
</profiles>

 打包命令:

mvn package -Pproduction

maven中跳过单元测试,布布扣,bubuko.com

maven中跳过单元测试

原文:http://www.cnblogs.com/amosli/p/3573499.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!