Integration tests require access to external resources such as a relational database or a web service. In Maven, use the core Failsafe plugin to execute integration tests.
To configure, add the Failsafe plugin to the pom.xml in the <plugins> section.
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.13</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
To create a integration test, just create a Java class in the Maven test directory starting or ending with IT, e.g. ITWebService.java, DatabaseIT.java.
I usually disable integration tests by default since the external resources may be not operational and integration tests often take a long time to complete.
To disable by default, add the Maven skipITs property and set it to true.
<properties>
...
<skipITs>true</skipITs>
...
</properties>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.13</version>
<configuration>
<skipTests>${skipITs}</skipTests>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
To execute, run the command
mvn -DskipITs=false clean install
No comments:
Post a Comment