Question

I'm running the goal failsafe:integration-test on a multi-module project with the format:

Parent:
--------Module_A
--------Module_B

Consider a passing Test_B1_IT (in Module B) that tests something in Class_A1 (in Module A).

You now change Class_A1 and the test now fails. However, if you run the goal

mvn failsafe:integration-test

the test will still pass - changes aren't reflected until you run the deploy goal. I believe the goal is using the jar's from the repository, and not the most recent build from the current reactor.
If you run integration-test it works...but it seems to run all the unit tests as well (there doesn't seem to be a way to skip unit tests and run _IT integration tests).

I also see that it works for the goal integration-test or if I add "compile" before the failsafe goal. The first option, however, runs all tests (unit + integration)

Is this a problem with the failsafe plugin or just the way maven handles dependencies in multi-module projects? Should the best approach be to just add the compile option ?

Was it helpful?

Solution

The first thing is you can skip unit tests by simply given skip on command line like:

mvn -Dmaven.test.skip=true lifecycle

If you like to run integration test you shouldn't call the failsafe:integration-test goal, cause you are missing the pre-integration-test phase and the post-integration-test lifecylce phase.

A better approach is to use the reactor of Maven via calling

mvn -D... -am -pl Module_A  lifecylcephase

The -am switch will make sure to compile all dependant modules.

Furthermore i would suggest to put the integration tests into a separate module which makes life easier like:

 +-- root 
      +--- pom.xml
      +--- mod1 (pom.xml)
      +--- mod2 (pom.xml)
      +--- mod-it (pom.xml)

The mod-it can be activated by using a profile like:

mvn -Prun-its ...

What you wrote about using the module is true. If you just call a goal the dependencies will be resolved against the local repository and of course not via the reactor, cause there is not reactor running in that case.

Nevertheless the integration test phase assumes that all unit tests have already been run so it makes sense to run the unit tests first like Maven does by its lifecycle. But you can influence that by using some properties to control that in detail. But usually running the unit tests shouldn't be a problem cause unit tests must run fast.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top