Hi_Amos
坚持每天都在进步!!

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

 

 

 

 

posted on 2014-02-28 19:48  Hi_Amos  阅读(2227)  评论(0编辑  收藏  举报