Search code examples
maventestingmaven-surefire-pluginmaven-failsafe-plugin

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?


Solution

  • Here's a solution that does exactly what I want: using the Failsafe plugin to run just the integration tests without having to move tests out of their natural places or recompile in order to run the tests.

    mvn install -DskipITs
    mvn failsafe:integration-test
    

    We get Maven to publish the artifacts for the project into a local directory. We can then use that as a repository for the second step. In that second step we then invoke exactly the goal that we need and it grabs the artifacts from the local repository.

    The same thing works for Surefire (mvn surefire:test) if you need to run unit tests separately.

    I have to admit that I don't fully understand the Maven model and hence why this works. The internet seems unanimously of the view that this kind of thing can't be done (see other answers here), but it's definitely working for me.