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

后端 未结 2 2277
悲哀的现实
悲哀的现实 2021-02-19 18:44

My directory structure is like so:

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

I a

相关标签:
2条回答
  • 2021-02-19 19:32

    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.

    0 讨论(0)
  • 2021-02-19 19:37

    Got working integration tests on Groovy residing in src/test/groovy with this configuration:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>3.0.0-M5</version>
        <executions>
            <execution>
                <id>spock-integration-tests</id>
                <goals>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
                <configuration>
                    <failIfNoTests>true</failIfNoTests>
                    <testSourceDirectory>${project.basedir}/src/test/groovy</testSourceDirectory>
                    <includes>
                        <include>**/*Specification</include>
                    </includes>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    Note that pattern in <include> doesn't contain file extension (**/*Specification.groovy doesn't work)

    0 讨论(0)
提交回复
热议问题