配置maven-failsafe-plugin以查找不在src/test/java中的集成测试 [英] Configuring maven-failsafe-plugin to find integration tests not in src/test/java

查看:642
本文介绍了配置maven-failsafe-plugin以查找不在src/test/java中的集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目录结构如下:

  • src/integrationTest/java
  • src/test/java
  • src/main/java
  • src/integrationTest/java
  • src/test/java
  • src/main/java

我正在尝试通过故障保险来进行集成测试,但未能按照我想要的方式进行.

I am trying to get failsafe to pick-up the integration tests, but failing to do so in the way I would like.

我已经尝试过了:

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.17</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <testSourceDirectory>src/integrationTest/java</testSourceDirectory>
        <testClassesDirectory>${project.build.directory}/it-classes</testClassesDirectory>
    </configuration>
</plugin>

和这个:

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.17</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <includes>
            <include>src/integrationTest/**/*.java</include>
        </includes>
    </configuration>
</plugin>

无济于事; failsafe找不到要运行的测试.

to no avail; failsafe does not find tests to run.

我已经能够使用build-helper-maven插件添加一个test-source目录,然后使用failsafe运行测试.

I have been able to use the build-helper-maven plugin to add a test-source directory and then failsafe runs the tests.

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

但是,现在的问题是,surefire现在也将测试作为单元测试来运行.当故障安全应该能够找到测试时,似乎也不必使用其他插件.我不希望不需要使用build-helper maven插件并配置surefire来排除该路径.

However, the problem now is that surefire now also runs the tests as unit-tests. Also it seems unnecessary to use another plugin when failsafe should be able to find the tests; I would prefer to not to need to use build-helper maven plugin and configure surefire to exclude that path.

我在做什么错了?

推荐答案

默认情况下,故障保护配置为仅

By default failsafe is configured to only include IT*.java, *IT.java or *ITCase.java. While at the same time, only test sources from src/test/java are compiled. You need to modify both of these behaviors.

  1. 使用build-helper-maven-pluginsrc/integationTest/java添加为maven-compiler-plugin的测试源,以自动进行拾取. (您在上一次尝试中已经完成了此操作.)

  1. Use build-helper-maven-plugin to add src/integationTest/java as test source for maven-compiler-plugin to pick up automatically. (You've already done this in your last attempt.)

直接maven-surefire-plugin以排除集成测试(请参见下面的示例)或仅包括非集成测试(请参见

Direct maven-surefire-plugin to exclude your integration tests (see example below) or to include only non-integration tests (see default includes).

直接maven-failsafe-plugin仅包含集成测试,而不包括默认包含.

Direct maven-failsafe-plugin to only include your integration tests instead of default includes.


<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.17</version>
  <configuration>
    <excludes>
      <exclude>**/*Stuff.java</exclude>
    </excludes>
  </configuration>
</plugin>
<plugin>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.17</version>
  <executions>
    <execution>
      <goals>
        <goal>integration-test</goal>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <includes>
      <include>**/*Stuff.java</include>
    </includes>
  </configuration>
</plugin>

实际上,使用testClassesDirectory可能也可以用于限制每个测试插件的范围,但是您必须对maven-compiler-plugin进行更改以将类输出到不同的文件夹,也许将其test-compile执行拆分为两个,所以也许这是不值得的.

In fact using testClassesDirectory might also work for limiting scope of each test plugin, but you would have to make changes to maven-compiler-plugin to output classes to different folders, perhaps splitting it's test-compile execution into two, so maybe it's not worth the effort.

这篇关于配置maven-failsafe-plugin以查找不在src/test/java中的集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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