Search code examples
mavenmaven-failsafe-plugin

Why is failsafe: not executed with "mvn verify"?


Why is "failsafe:integration-test" not automatically executed with mvn verify?

According to mvn help:describe ... the maven-failsafe-plugin task "integraton-test" is supposed to be bound to the "integration-test" phase:

failsafe:integration-test
  Description: Run integration tests using Surefire.
  Implementation: org.apache.maven.plugin.failsafe.IntegrationTestMojo
  Language: java
  Bound to phase: integration-test

Yet mvn verify only executes "surefire:test" but not "failsafe:integration-test".

I do know how to fix that using <executions> as this is even in the "Usage" examples on the failsafe plugin homepage but I would like to understand why the two plugins behave differently.

There are file that match both <include> patterns:

src/test/java/de/lathspell/test/UselessThingTest.java
src/test/java/de/lathspell/test/UselessThingIT.java  

My pom.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pom="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.lathspell</groupId>
    <artifactId>test1</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

The output:

[INFO] -------------------------< de.lathspell:test1 >-------------------------
[INFO] Building test1 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /mnt/keller_christian/workspace/test1/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /mnt/keller_christian/workspace/test1/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ test1 ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running de.lathspell.test.UselessThingTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.048 s - in de.lathspell.test.UselessThingTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test1 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Solution

  • The simple things is that maven-failsafe-plugin is not bound to any kind of life cycle by default.

    This means you have to bind that yourself within your project once.

    The documentation says:

    Binds by default to the lifecycle phase: integration-test.

    Which means you have to add to the life cycle at all and then the plugins will bind to integration-test life cycle.

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

    After this you should execute your integration tests simply by using the following:

    mvn clean verify
    

    Update: If the documentation of a plugins says:

    Binds by default to the lifecycle phase: x

    this means only it is bound to the give life cycle phase if you add an execution as above but have not defined <phase>..</phaseY>. This is a kind of default which you don't give explicitly in your pom configuration.