Search code examples
mavenintegration-testingmaven-failsafe-plugin

Why don't my integration tests run while invoking the "mvn test" command?


Currently my integration tests only run when I run mvn install. I would like to have them run when I do mvn test.

My <pluginManagement> section contains:

<pluginManagement>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18.1</version>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    ...
</pluginManagement>

How can I make the integration tests run when I give only the goal test?


Solution

  • Actually there is special phases for running integration tests:

    • pre-integration-test - configure test environment.
    • integration-test - run the tests.
    • post-integration-test - stop integration test environment.
    • verify - check the results.

    They run sequentially, so if you call

    mvn integration-test
    

    and it fails, post-integration-test phase won't be invoked.

    But if you want to call it within the "test" phase, just move the tests to the appropriate phase:

        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.18.1</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    <phase>test</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>