8

如何在 pom 中设置不在 Maven 中编译测试?我试过了:

<properties>
  <skipTests>true</skipTests>
</properties>

但在这种情况下,Maven 编译测试但不运行它们。我需要 Maven 不要编译我的测试。

4

4 回答 4

8

您必须将 maven.test.skip 定义为 true。

<properties>
    <maven.test.skip>true</maven.test.skip>
</properties>

http://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-test.html

于 2013-04-04T21:16:47.627 回答
0

如果您正在使用surefire-plugin执行测试,您可以将其配置为根据命名模式跳过它们:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.14</version>
        <configuration>
          <includes>
            <include>%regex[.*[Cat|Dog].*Test.*]</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

但是,这要求测试文件名符合所需的模式。在工作中,我们正在使用这种方法,并让我们的测试以..UnitTestor结尾..IntegrationTest,这样我们就可以通过修改相应构建配置文件中的正则表达式来轻松关闭它们中的每一个。

看看Apache关于surefire 插件的文档。您可能会发现一些更有用或更适合您的情况的东西。

于 2013-04-04T21:08:48.337 回答
0

配置 maven-compiler-plugin 以跳过编译。再一次,我不推荐它。

<project>
  <properties>
    <maven.test.skip>true</maven.test.skip>
  </properties>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
        <executions>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <skip>${maven.test.skip}</skip>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
于 2013-04-04T21:18:38.207 回答
0

在我的情况下,一个解决方案是将测试放在配置文件中(例如 runTests),所以当我想运行这些测试时,我添加了参数-PrunTests. 感谢您的回复。

于 2013-07-04T20:39:49.257 回答