1

I am attempting to have my integration tests separated from the usual lifecycle, meaning that I do not want them to be executed during a mvn install. I have the following configuration:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <configuration>
            <excludes>
                <exclude>**/*IT.java</exclude>
            </excludes>
        </configuration>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <configuration>
            <includes>
                <include>**/*IT.java</include>
            </includes>
        </configuration>
        <goals>
           <goal>integration-test</goal>
        </goals>
    </plugin>

And my integration tests are all suffixed with IT. I was able to confirm that surefire does exclude the *IT.java tests, however it seems that failsafe is being triggered during mvn install anyway. What am I missing?

Thank you for your help

João Matos
  • 6,102
  • 5
  • 41
  • 76
  • 1
    First you excluding/including this in both plugins which are there by default. and yes using `mvn install` will execute failsafe-plugin cause it's bound to integration-test phase....To execute integration test you should usually only use `mvn clean verify` ... – khmarbaise Feb 20 '20 at 10:27
  • But how do I exclude them from mvn install? – João Matos Feb 20 '20 at 10:32
  • If you like to prevent running integration tests you have to use a profile... – khmarbaise Feb 20 '20 at 10:36
  • What are you trying you do? `install` phase comes after the `verify` phase in maven and this `verify` phase will do the integration tests. And when you execute `mvn install`, maven will, by default, execute `verify` phase before it executes `install` phase? – Alanpatchi Feb 20 '20 at 13:26
  • My goal is to 1) run 'mvn install' to do everything except run the integration tests; 2) run 'mvn xxxxxx' to run the integration tests. – João Matos Feb 20 '20 at 13:29

1 Answers1

2

A typical configuration to handle the issue with running integration tests only if you like is a profile like the following:

<profiles>
   <profile>
      <id>run-its</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

By using the above configuration you can run

mvn clean verify 

which will execute the unit tests. Using the following you can activate the integration tests:

mvn -Prun-its clean verify

Based on the default naming conventions the integration tests which will be executed by maven-failsafe-plugin should be named like *IT.java where as the unit tests can be name like *Test.java (will be executed via maven-surefire-plugin).

khmarbaise
  • 92,914
  • 28
  • 189
  • 235