Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
Maven User
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h1>Integration and Functional Testing with Maven 2.0</h1><h2>Intro</h2><p>"<em>The Failsafe Plugin is designed to run integration tests while the Surefire Plugins is designed to run unit tests.</em>" - <a href="http://maven.apache.org/plugins/maven-failsafe-plugin/">http://maven.apache.org/plugins/maven-failsafe-plugin/</a></p><p>See below for <a class="confluence-link" href="#MavenandIntegrationTesting-UsingtheMavenFailsafePlugintorunIntegrationTests" data-anchor="MavenandIntegrationTesting-UsingtheMavenFailsafePlugintorunIntegrationTests" data-linked-resource-default-alias="MavenandIntegrationTesting-UsingtheMavenFailsafePlugintorunIntegrationTests" data-base-url="http://docs.codehaus.org">the Failsafe section</a>.</p><p>However, some people are using Surefire for integration testing - not least because Failsafe only came along some time after Surefire ...</p><h2>Put your Integration tests in a separate module</h2><p>Better Builds With Maven describes a single example module containing only integration tests. In the case of a multi-module "reactor" project, where each module may need some integration testing, you have some choices available to you.</p><h3>Create Multiple Integration Test POMs</h3><p>You can, if you wish, create multiple integration test modules, one for each source module in your project. For example, if you've got two child projects "foo" and "bar", you could create a "foo-integration-test" module and a "bar-integration-test" module to test "foo" and "bar" respectively.</p><p>The advantage of doing it this way is that it's very clear which integration tests belong to which project. It's also easy for project owners to know which integration tests they're responsible for. The big drawback here is that you've just doubled the number of POM files in your reactor, which can be difficult to manage. Each project will need to be separately referenced in the root POM.</p><h3>Put all Integration Tests into One Big Module</h3><p>This is obviously much simpler to wire up in a POM file; simplicity is a virtue in project management.</p><p>The disadvantage of doing it this way is that it tends to separate the integration tests from the code they're attempting to test. As a result, you may find that no one "owns" the integration tests; typically you'll have some one person whose job it is to analyze the integration tests and find bugs. QA is hard, but it's even harder when it's unclear who "owns" test failures.</p><h2>Alternatives to Isolating the Integration Tests</h2><p>If for some reason you can't put the integration tests in a separate module, here are some ideas.</p><h3>Integration Tests Only</h3><p>If you have <strong>only</strong> integration tests in the same module as your webapp, you can configure Surefire to skip the test phase, then run in the integration-test phase. See <a href="http://docs.codehaus.org/pages/viewpage.action?pageId=62120">this page</a>.</p><h3>Both Unit and Integration Tests in the Same Module</h3><p>If you need to run both unit and integration tests in the same module, it's possible, just not very pretty.</p><p>There is only one testSourceDirectory per module, so all of your test classes must reside in one directory structure, usually src/test/java.</p><p>In the 'test' phase, configure Surefire to exclude the tests in (for example) <code>**</code><code><strong>/systest/</strong></code><code>**</code>.</p><p>Bind another execution of maven-surefire-plugin to the integration-test phase, and reverse the exclusion pattern.</p><p>You can see an example of this in the Shale Usecases example app <a href="http://svn.apache.org/repos/asf/shale/framework/trunk/shale-apps/shale-usecases/pom.xml">pom.xml</a> file.</p><h3>Using the Maven Failsafe Plugin to run Integration Tests</h3><p>The <a href="http://maven.apache.org/plugins/maven-failsafe-plugin/">Maven Failsafe Plugin</a> is a fork of the Maven Surefire Plugin designed to help when running integration tests.</p><p>If you use this approach, you keep all your tests for a module in the testSourceDirectory, e.g. src/test/java. By default the Failsafe Maven Plugin looks for integration tests matching the patterns *<strong>/IT</strong>.java, **/<strong>IT.java and *</strong>/*ITCase.java. You will notice that these bindings do not overlap with the default surefire bindings. To use the Maven Failsafe Plugin you need to add the following to your <a href="http://svn.apache.org/repos/asf/shale/framework/trunk/shale-apps/shale-usecases/pom.xml">pom.xml</a> file.</p><table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><project> [...] <build> <plugins> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> </plugins> </build> [...] </project> </pre></td></tr></table><p>You will then have the following lifecycle bindings</p><table class="confluenceTable"><tbody><tr><th class="confluenceTh"><p>Phase</p></th><th class="confluenceTh"><p>Plugin execution goal</p></th></tr><tr><td class="confluenceTd"><p>test</p></td><td class="confluenceTd"><p>surefire:test</p></td></tr><tr><td class="confluenceTd"><p>integration-test</p></td><td class="confluenceTd"><p>failsafe:integration-test</p></td></tr><tr><td class="confluenceTd"><p>verify</p></td><td class="confluenceTd"><p>failsafe:verify</p></td></tr></tbody></table><p>The advantage to using the Maven Failsafe Plugin is that it will not stop the build <strong>during the integration-test phase</strong> if there are test failures. The recommendation is that you do not directly invoke the <strong>pre-integration-test</strong>, <strong>integration-test</strong> or <strong>post-integration-test</strong> phases but that instead you run integration tests by specifying the <strong>verify</strong> phase, e.g.</p><table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>mvn verify </pre></td></tr></table><p>This allows you to set-up your integration test environment during the <strong>pre-integration-test</strong> phase, run your integration tests during the <strong>integration-test</strong> phase, <em>cleanly tear-down</em> your integration test environment during the <strong>post-integration-test</strong> phase before finally checking the integration test results and failing the build if necessary. Here is an example using jetty for hosting an integration test environment:</p><table class="wysiwyg-macro" data-macro-name="noformat" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e25vZm9ybWF0fQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre><project> [...] <build> <plugins> <plugin> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.16</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <stopPort>8005</stopPort> <stopKey>STOP</stopKey> <contextPath>/</contextPath> </configuration> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <scanIntervalSeconds>0</scanIntervalSeconds> <daemon>true</daemon> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> </pre></td></tr></table><h2>The Future</h2><p>Rumor has it that a future version of Maven will support something like src/it/java in the integration-test phase, in addition to src/test/java in the test phase.</p><h2>External Links</h2><h3>Surefire</h3><ul><li><a href="http://stackoverflow.com/questions/1399240/how-do-i-get-my-maven-integration-tests-to-run">How do I get my Maven Integration tests to run?</a></li><li><a href="http://stackoverflow.com/questions/412717/how-to-use-maven-surefire-plug-in-with-different-groups-for-test-and-integration">How to use Maven Surefire plug-in with different groups for test and integration-test?</a></li><li><a href="http://onjavahell.blogspot.com/2009/05/integration-testing-with-maven-20.html">Integration testing with maven 2.0</a></li></ul><h3>Failsafe</h3><ul><li><a href="http://www.sonatype.com/people/2009/06/integration-tests-with-maven-part-1-failsafe-plugin/">Integration tests with Maven (Part 1): Failsafe Plugin</a></li></ul><h2>Related Articles</h2><ul class="alternate"><li><a href="http://docs.codehaus.org/display/MAVEN/best+practices+-+testing+strategies">Best Practices - Testing Strategies</a></li><li><a href="http://docs.codehaus.org/display/MAVEN/Testing+Strategies">Testing Strategies</a></li></ul>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced