如何在src/test-integration/java文件夹中的Maven中运行UnitTests [英] How to run UnitTests in maven which is in src/test-integration/java folder

查看:64
本文介绍了如何在src/test-integration/java文件夹中的Maven中运行UnitTests的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们说mvn test时,通常的方法是maven查找src/test/java文件夹中存在的测试.但是我将测试放在其他文件夹中,即src/integration-test/java.如何通过命令行运行此文件夹中存在的测试?

预先感谢

Manoj.

解决方案

首先,您不应该通过 test maven-failsafe-plugin 是负责任的. /p>

有几种方法可以处理您的情况.首先,您应该遵循命名约定用于集成测试

<includes>
 <include>**/IT*.java</include>
 <include>**/*IT.java</include>
 <include>**/*ITCase.java</include>
</includes>

表示将集成测试放入默认文件夹 src/test/java .如果您有一个多模块构建,最好是有一个仅包含集成测试的单独模块,或者您可以决定使用一个单独的文件夹(不是最好的):

首先,您需要使用 buildhelper-maven-plugin 使这些集成测试按如下方式编译:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
      <execution>
        <id>add-test-source</id>
        <phase>process-resources</phase>
        <goals>
          <goal>add-test-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>src/integration-test/java</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>

,您必须像这样配置maven-failsafe-plugin:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.14.1</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

配置完成后,您可以通过以下方式运行集成测试:

mvn verify

When we say mvn test, usual way is that maven will look for the tests present in src/test/java folder. But I have my tests in some different folder, namely src/integration-test/java. How do I run the tests present in this folder through command line?

Thanks in advance,

Manoj.

解决方案

First you shouldn't run those integration test via the test life cycle, cause pre-integration-test, integration-test and post-integration-test life cycle phase exist. Apart from that for integration tests the maven-failsafe-plugin is responsible.

There are several options to handle your situations. First you should follow the naming conventions for integration tests

<includes>
 <include>**/IT*.java</include>
 <include>**/*IT.java</include>
 <include>**/*ITCase.java</include>
</includes>

which means to put the integration tests into the default folder src/test/java. If you have a multi-module build it would be the best having a separate module which contains the integration-tests only or you can go the path you decided to use a separate folder (which is not the best):

First you need to add the folder using the buildhelper-maven-plugin to get those integration tests being compiled like this:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
      <execution>
        <id>add-test-source</id>
        <phase>process-resources</phase>
        <goals>
          <goal>add-test-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>src/integration-test/java</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>

and you have to configuration the maven-failsafe-plugin like this:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.14.1</version>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

After you have configured you can run your integration tests via:

mvn verify

这篇关于如何在src/test-integration/java文件夹中的Maven中运行UnitTests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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