maven中跳过单元测试

    你可能想要配置 Maven 使其彻底跳过单元测试。 可能你有一个很大的系统,单元测试须要花好多分钟来完成,而你不想在生成最终输出前等单元测试完成。 你可能正工做在一个遗留系统上面,这个系统有一系列的失败的单元测试,你可能仅仅想要生成一个 JAR 而不是去修复全部的单元测试。 

Maven 提供了跳过单元测试的能力:

方法1、使用命令行方式

    只须要使用 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 ,它就会跳过单元测试 apache

方法2、配置pom.xml文件

你须要为你的 build 添加 plugin 元素
maven

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
相关文章
相关标签/搜索