在Maven的某些模块中跳过测试 [英] Skipping tests in some modules in Maven

查看:454
本文介绍了在Maven的某些模块中跳过测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Maven构建可以运行大多数单元测试.但是在一个项目中有一些单元测试要慢一些,因此我想将它们排除在外.并偶尔将它们打开.

I would like my Maven builds to run most unit tests. But there are unit tests in one project which are slower and I'd like to generally exclude them; and occasionally turn them on.

问题:我该怎么做?

我了解-Dmaven.test.skip=true,但是这会关闭所有单元测试.

I know about -Dmaven.test.skip=true, but that turns off all unit tests.

我也了解跳过集成测试的情况,此处 .但是我没有集成测试,只有单元测试,也没有对maven-surefire-plugin的任何明确调用. (我将Maven 2与Eclipse-Maven插件一起使用).

I also know about skipping integration tests, described here. But I do not have integration tests, just unit tests, and I don't have any explicit calls to the maven-surefire-plugin. (I am using Maven 2 with the Eclipse-Maven plugin).

推荐答案

仅在此模块中跳过测试怎么办?

What about skipping tests only in this module ?

在此模块的pom.xml中:

In the pom.xml of this module:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.4.2</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

最终,您可以创建一个配置文件来禁用测试(仍然是模块的pom.xml):

Eventually, you can create a profile that will disable the tests (still the pom.xml of the module) :

<project>
  [...]
  <profiles>
    <profile>
      <id>noTest</id>
      <activation>
        <property>
          <name>noTest</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.2</version>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  [...]
</project>

对于后一种解决方案,如果运行mvn clean package,它将运行所有测试.如果运行mvn clean package -DnoTest=true,它将不会运行此模块的测试.

With the latter solution, if you run mvn clean package, it will run all tests. If you run mvn clean package -DnoTest=true, it will not run the tests for this module.

这篇关于在Maven的某些模块中跳过测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆