I am working on a large multi-module Maven project. Each module has fast unit tests (using the Surefire plugin), many modules have slow integration tests (using the Failsafe plugin).
I would like to speed up the feedback for "simple" build failures (compilation errors and unit test failures) by running integration tests from all modules after all modules have been built and unit-tested.
Can you suggest a good way of achieving this?
The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.
The Maven build lifecycle now includes the "integration-test" phase for running integration tests, which are run separately from the unit tests run during the "test" phase. It runs after "package", so if you run "mvn verify", "mvn install", or "mvn deploy", integration tests will be run along the way.
A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.
running integration tests from all modules after all modules have been built and unit-tested
To meet this requirement a possible solution is to have an additional (optional) module providing integration tests, that is, all integration tests should be moved to this module, which could be added to the default build via a profile.
<profiles>
<profile>
<id>it</id>
<modules>
...
<module>it-module</module>
</modules>
</profile>
</profiles>
In order to have it as last step of the build for the Maven Reactor, this module should also depend on all other modules (probably it would implicitly already be the case).
This module would actually be the only one providing maven-failsafe-plugin
configuration and settings. Moreover, it might become more meaningful in case of the usage of an embedded server to test against (i.e. Jetty): the server will be created and shutted down only during the build of this module and not in each and every module requiring it, speeding up this integration phase.
Being the last module of the build, you will make sure that it would be reached only in case of no unit test failures on previous modules and only when the it
profile would be active (e.g. during CI builds).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With