Nital
Nital

Reputation: 6114

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

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?

Upvotes: 2

Views: 285

Answers (2)

src3369
src3369

Reputation: 2049

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.

Upvotes: 1

dunni
dunni

Reputation: 44555

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.

Upvotes: 4

Related Questions