Quantcast
Channel: Java Team at Kentor » Frameworks
Viewing all articles
Browse latest Browse all 26

Integration test with Maven

$
0
0

integration-test is a phase in Maven life-cycle. This is after the well-known ‘package‘ phase and before the ‘install‘ phase. Here one could fix the dependencies required in other to run the integration test like database; server; copying to a location etc.

process and deploy the package if necessary into an environment where integration tests can be run

With a simple example we can see how can we turnoff running integration test in default test phase and run them only in integration-test phase (after the package has been generated!). Otherwise the default-test will report failure since the test are dependent on resources. Here goes the maven configuration.

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<configuration>
<skipTests>true</skipTests>
</configuration>
</execution>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>

Now in the integration-test assuming you are using tomcat; need to configure pre-integration-test phase (start server) and post-integration-test phase (shutdown server).

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>

Other related post on Maven basics and plugins on this blog



Viewing all articles
Browse latest Browse all 26

Trending Articles