Skip to content

Integration Test with Maven

June 25, 2009
tags:

A collection of posts found on the internet focusing on how to tweak/enhance Maven to perform integration tests.

  1. Integration testing with maven 2.0 – by Julien Dechmann
  2. Getting Coverage For Integration Tests – by Ulrik Sandberg
  3. Integration tests with Maven (Part 1): Failsafe Plugin – by velo
  4. Unit tests are not integration tests – by John Ferguson Smart
  5. Maven Integration Testing – by Rod Coffin
  6. Maven and Integration Testing – from codehaus



Post I: Integration testing with maven 2.0

See the original post at here.

The idea described in this post is to customize “maven surefire plugin”. In simple words, the idea is to configure “maven surefire plugin” to only include integration test classes in the maven integration-test phase. Details are:

  • Put integration test related classes in a particular folder that is different from the folder which contains unit test classes.
  • Configure the “maven surefire plugin” such that integration test classes are excluded from being executed at maven test phase.
  • Configure the “maven surefire plugin” to bind the maven integration-test phase with integration test classes.



A sample configuration looks like the following

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <excludes> <exclude>**/integration/*Test.java</exclude> </excludes> </configuration> <executions> <execution> <id>integration-tests</id> <phase>integration-test</phase> <goals> <goal>test</goal> </goals> <configuration> <skip>false</skip> <excludes> <exclude>none</exclude> </excludes> <includes> <include>**/integration/*Test.java</include> </includes> </configuration> </execution> </executions> </plugin>



One thing to note about this approach is that integration test classes will also have to exist under the src/test/java folder, otherwise you will have to include the folder which contains integration test classes into the “test source”. We will see this approach in the next case.




Post II: Getting Coverage For Integration Tests

See the original post at here.

The idea described in this post is to customize the “test source” directory to include integration test classes when a particular profile is enabled. Details are:

  • Put integration test related classes in a particular folder (possibly outside of src/test/java) that is different from the folder which contains unit test classes.
  • Configure the “build helper maven plugin” to add this folder into one of “test source” directories at maven generate-sources phase.
  • Configure a profile and put the above mentioned “build helper maven plugin” inside this profile.
  • Use “-P profile_name” to enable this profile when executing maven test phase.
    For example, “mvn test -P it”.



A sample configuration looks like the following

<profiles> <profile> <id>it</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>add-test-source</id> <phase>generate-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/it/java</source> </sources> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>



One thing to note about this approach is that integration test classes are still being executed during the maven test phase, instead of at the maven integration-test phase.

We can however combine the both approaches to only include integration test classes when a particular profile is enabled and have these tests executed at the maven integration-test phase.




Post III: Integration tests with Maven (Part 1): Failsafe Plugin

See the original post at here.

The third approach is much simpler. The idea is to configure a “failsafe maven plugin” to execute integration test classes at the maven integration-test phase. Details are:

  • Configure a “failsafe maven plugin”.



That is it!. By default, this plugin will look for **/*IT.java, **/IT*.java and **/*ITCase.java files under src/test/java directory.

A sample configuration looks like the following

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>failsafe-maven-plugin</artifactId> <version>2.4.3-alpha-1</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal>                             </goals> </execution> </executions> </plugin>



If integration test classes exist outside of src/test/java directory, we can combine this approach together with the profile approach to include such classes into “test source” directories.




Post IV: Unit tests are not integration tests

See the original post at here.

The idea is pretty similar to what is described in Post I. The idea is to skip the default maven test and bind another two executions. Details are:

  • Configure the “maven surefire plugin” such that default maven test phase is skipped.
  • Configure the “maven sure fire plugin” to bind a new execution at maven test phase and also exclude integration test classes.
  • Configure the “maven sure fire plugin” to bind another new execution at maven integration test phase and also only include integration test classes.

A sample configuration looks like the following

<plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> <executions> <execution> <id>unit-tests</id> <phase>test</phase> <goals> <goal>test</goal> </goals> <configuration> <skip>false</skip> <excludes> <exclude>**/*IntegrationTest.java</exclude> </excludes> </configuration> </execution> <execution> <id>integration-tests</id> <phase>integration-test</phase> <goals> <goal>test</goal> </goals> <configuration> <skip>false</skip> <includes> <include>**/*IntegrationTest.java</include> </includes> </configuration> </execution> </executions> </plugin>



Post V: Maven Integration Testing

See the original post at here.

What is described in this post is similar to the configuration described in Post I and Post IV.




Post VI: Maven and Integration Testing

This post summarized most of the ideas described so far.




About these ads
One Comment leave one →
  1. February 11, 2013 12:37 pm

    just stopped by to check out this site. It appears
    really full of great content and I had a good time browsing it, thank you for the good information!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: