Maven Integration Tests

Unit tests shouldn’t take long to complete and by definition should test a unit in isolation. Therefore unit tests shouldn’t include database or web framework resources.

Integration Testing is responsible putting everything together and check whether things work as expected. Maven has a special phase in its lifecycle called integration-tests that accommodates and executes integration related tests by calling mvn integration-test. A nice technique a colleague suggested is to have a name convention for integration tests and explicitly exclude/include during related phases in the Maven Surefire plugin. Assuming the naming convention referring to classes meant to be Integration Tests have the “IntegrationTest” suffix, the POM configuration of the maven-surefire-plugin would look something like this:

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

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