Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run integration tests after building all modules in a multi-module Maven project?

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?

like image 468
Ben Butler-Cole Avatar asked Sep 21 '16 09:09

Ben Butler-Cole


People also ask

How do I run an integration-test in Maven?

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.

Does mvn install run integration tests?

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.

What is the use of multi-module project in Maven?

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.


1 Answers

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).

like image 156
A_Di-Matteo Avatar answered Oct 29 '22 17:10

A_Di-Matteo