Configuring maven-failsafe-plugin to find integration tests not in src/test/java

☆樱花仙子☆ 提交于 2019-12-10 03:26:29

问题


My directory structure is like so:

  • 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.

I have tried this:

<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>

and this:

<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>

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

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>

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.

What am I doing wrong?


回答1:


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. 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.)

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

  3. 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>

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.



来源:https://stackoverflow.com/questions/38398323/configuring-maven-failsafe-plugin-to-find-integration-tests-not-in-src-test-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!