------
Usage
------
Stephen Connolly
Brett Porter
Allan Ramirez
------
May 2009
------
Usage
To use the Failsafe Plugin, you need to add the following configuration to
your pom.xml
+---+
[...]
org.apache.maven.plugins
maven-failsafe-plugin
${project.version}
integration-test
integration-test
verify
verify
[...]
+---+
Then Failsafe Plugin can be invoked by calling the <<>> phase of the
build lifecycle.
+---+
mvn verify
+---+
* Using different testing providers
Tests in your test source directory can be any combination of the following:
* TestNG
* JUnit (3.8 or 4.x)
* POJO
Which providers are available is controlled simply by the inclusion of the
appropriate dependencies (ie, junit:junit for JUnit, org.testng:testng 4.7+
for TestNG). Since this is required to compile the test classes anyway, no
additional configuration is required.
Note that any normal Surefire integration works identically no matter which
providers are in use - so you can still produce a Cobertura report and a
Surefire results report on your project web site for your TestNG tests,
for example.
The POJO provider above allows you to write tests that do not depend on
JUnit. They behave in the same way, running all <<>> methods that are
public in the class, but the API dependency is not required. To perform
assertions, the JDK 1.4 <<>> keyword can be used, or you can use
<<>>.
All of the providers support the Surefire Plugin parameter configurations.
However, there are additional options available if you are running TestNG
tests (including if you are using TestNG to execute your JUnit tests, which
occurs by default if both are present in Surefire).
See {{{examples/testng.html} Using TestNG}} for more information.
* Using jetty and maven-failsafe-plugin
You need to bind one of <<>>, <<>> or <<>>
to the <<>> phase with <<>> set to true, bind
<<>> to the <<>> phase, bind <<>>
to the <<>> phase and finally bind <<>> to
the <<>> phase. Here is an example:
+---+
[...]
[...]
[...]
org.apache.maven.plugins
maven-failsafe-plugin
${project.version}
integration-test
integration-test
verify
verify
org.mortbay.jetty
maven-jetty-plugin
6.1.16
[...]
[...]
10
8005
STOP
/
[...]
[...]
[...]
start-jetty
pre-integration-test
run-exploded
0
true
stop-jetty
post-integration-test
stop
[...]
[...]
[...]
[...]
[...]
+---+
You then invoke maven with a phase of <<>> or later in order to run
the integration tests. DO NOT directly invoke any of the phases:
<<>>, <<>>, or <<>> as
these are too long to type and they will likely leave a jetty container running.
+---+
mvn verify
+---+
Note: during test development, you will likely run a jetty instance in the background.
to help running the integration tests, it can be handy to bind <<>> to
the <<>> phase before <<>> to flush out any
running jetty instance before starting the integration test jetty instance, e.g.
+---+
[...]
[...]
[...]
org.mortbay.jetty
maven-jetty-plugin
6.1.16
[...]
[...]
start-jetty
pre-integration-test
stop
run-exploded
[...]
[...]
[...]
[...]
[...]
[...]
+---+
* Reporting integration test results
The Failsafe Plugin uses the exact same format as the Surefire Plugin, so to generate a report you just add a second
Surefire Report Plugin report set using the Failsafe reports directory, e.g.
+---+
[...]
org.apache.maven.plugins
maven-surefire-report-plugin
${project.version}
integration-tests
report-only
failsafe-report
${project.build.directory}/failsafe-reports
[...]
+---+
* Running integration tests multiple times
If you need to run your integration tests multiple times, just use multiple executions of the <<>>
goal. You will need to specify a different summary file for each execution, and then configure the <<>> goal
with the multiple summary files in order to fail the build when any one execution has failures, e.g.
+---+
[...]
org.apache.maven.plugins
maven-failsafe-plugin
${project.version}
integration-test-red-bevels
integration-test
red
target/failsafe-reports/failsafe-summary-red-bevels.xml
integration-test-no-bevels
integration-test
none
target/failsafe-reports/failsafe-summary-no-bevels.xml
verify
verify
target/failsafe-reports/failsafe-summary-red-bevels.xml
target/failsafe-reports/failsafe-summary-no-bevels.xml
[...]
+---+