Skip to content

Instantly share code, notes, and snippets.

@m0j0hn
Created June 15, 2016 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m0j0hn/3f8e1d6e43bf090bc65e1acbb0f5f52a to your computer and use it in GitHub Desktop.
Save m0j0hn/3f8e1d6e43bf090bc65e1acbb0f5f52a to your computer and use it in GitHub Desktop.
http://stackoverflow.com/questions/6612344/prevent-unit-tests-in-maven-but-allow-integration-tests
The maven-failsafe-plugin is for running Integration Tests.
Integration Tests, according to Maven lifecycle definition, come after Unit Tests - and after packaging.
And the maven-failsafe-plugin provides hooks to call code to install those packages, and reliably spin-up and tear-down services used by the Integration Tests regardless of success/failure of the test.
This is something the maven-surefire-plugin Unit Test plugin does not do, as it expects all its operations to be wholly confined to the JVM
My intent in adding the maven-failsafe-plugin is to give us better control over our tests, and to provide an easy way to migrate slow, non-Unit Tests to a different test harness, to be run after Unit Tests have passed. Once the maven-failsafe-plugin is available, this is as simple as renaming tests from Test.java or *Test.java to IT.java or *IT.java. And I will note that there are already some tests which match the IT naming rules, and in my testing they were properly found and run.
Finally, I have added some additional properties to allow us to selectively run all tests, only Unit Tests, only Integration Tests, or no tests at all. And in my testing these all work as expected.
Please let me know if you have any questions or comments.
#In parent/pom.xml:
<properties>
<!-- Order to run tests. 'filesystem' is the default -->
<failsafe.runOrder>filesystem</failsafe.runOrder>
<surefire.runOrder>filesystem</surefire.runOrder>
<!-- Properties to enable/disable tests -->
<!-- the "skipTests" property is implicitly used by Failsafe & Surefire plugins; default=undefined=>false -->
<skipUnitTests>${skipTests}</skipUnitTests> <!-- let -DskipTests skip Unit tests -->
<skipIntegrationTests>${skipTests}</skipIntegrationTests> <!-- let -DskipTests skip Integration tests -->
<skip.surefire.tests>${skipUnitTests}</skip.surefire.tests> <!-- let -DskipUnitTests skip Unit tests *only* -->
<skip.failsafe.tests>${skipIntegrationTests}</skip.failsafe.tests> <!-- let -DskipIntegrationTests skip Integration tests *only* -->
<version.maven-failsafe-plugin>2.19.1</version.maven-failsafe-plugin>
<version.maven-surefire-plugin>2.16</version.maven-surefire-plugin>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.maven-failsafe-plugin}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<runOrder>${failsafe.runOrder}</runOrder>
<skipTests>${skip.failsafe.tests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.maven-surefire-plugin}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<runOrder>${surefire.runOrder}</runOrder>
<skipTests>${skip.surefire.tests}</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment