Reputation: 3528
To my understanding, by default (that means without any explicit configuration of the failsafe plugin), maven should run integration tests when the goal "install" is executed. See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference.
Anyway, it seems to do not so. So, possibly I am misunderstanding something.
I made up a minimal test project with a JUnit test class org.example.ExampleIT in src/test/java and the following POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>mvn-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
The build (mvn install) is succesful, but failsafe is not executed. See the following log excerpt:
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mvn-project ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mvn-project ---
(...)
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mvn-project
(...)
[INFO] BUILD SUCCESS
Upvotes: 0
Views: 1159
Reputation: 3528
See https://maven.apache.org/ref/3.2.2/maven-core/default-bindings.html.
Plugins are bound to lifecycles phases by a "Plugin Binding". Those bindings are specific to the packaging.
The default bindings are defined in META-INF/plexus/default-bindings.xml in maven core. The default binding for jar packaging does not provide any plugin binding for the integration-test phase (see https://maven.apache.org/ref/3.2.2/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging), for that reason the binding of the failsafe plugin to the integration-test and verify phases must be configured manually (see answer from JF Meier).
The plugin must not only be bound to the integration-test phase, but to the verify phase, too. Otherwise the tests are executed, but the build does not fail if some integration test fails.
Upvotes: 1
Reputation: 35805
You should actually execute the plugin by
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
You can find more information on:
http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html
Upvotes: 2