Is it mandatory to specify maven-failsafe-plugin to run integration tests?

313 views Asked by At

Sorry about this very basic questions about maven-failsafe-plugin but I am not very much familiar with maven.

  1. Is it mandatory to specify maven-failsafe-plugin to run integration tests?
  2. Why can't mvn verify execute integration tests just like mvn test executes unit tests?
  3. Can integration tests be executed without this plugin?
2

There are 2 answers

0
dunni On BEST ANSWER

mvn test executes the unit tests, because Maven has a default binding from test to surefire:test, meaning, if you execute the phase test, Maven will call the surefire plugin with the goal test. However, there is no default binding for the integration test or verify phase, so you have to provide it yourself by specifying the failsafe plugin.

0
src3369 On

Completely Agree with dunni's answer. Adding few more points.

  1. It would be good practice to use maven-failsafe-plugin to run integration tests. As the Failsafe Plugin is designed to run integration tests while the Surefire Plugin is designed to run unit tests.
  2. This has been correctly answered by dunni.
    Addiing additional info, To use the Failsafe Plugin, you need to add the following configuration to your project pom.xml:

    <build>
        <plugins>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${maven-failsafe-plugin-version}</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
    1. Though it is not a good practise, you could configure maven-surefire-plugin to also run the integration tests without the failsafe-plugin.