I found the simplest way to skip only surefire tests is to configure surefire (but not failsafe) as follows:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<!-- skips surefire tests without skipping failsafe tests.
Property value seems to magically default to false -->
<skipTests>${skip.surefire.tests}</skipTests>
</configuration>
</plugin>
This allows you to run mvn verify -Dskip.surefire.tests
and only surefire, not failsafe, tests will be skipped; it will also run all other necessary phases including pre-integration and post-integration, and will also run the verify
goal which is required to actually fail your maven build if your integration tests fail.
Note that this redefines the property used to specify that tests should be skipped, so if you supply the canonical -DskipTests=true
, surefire will ignore it but failsafe will respect it, which may be unexpected, especially if you have existing builds/users specifying that flag already. A simple workaround seems to be to default skip.surefire.tests
to the value of skipTests
in your <properties>
section of the pom:
<properties>
<skip.surefire.tests>${skipTests}</skip.surefire.tests>
</properties>
If you need to, you could provide an analagous parameter called skip.failsafe.tests
for failsafe, however I haven't found it necessary - because unit tests usually run in an earlier phase, and if I want to run unit tests but not integration tests, I would run the test
phase instead of the verify
phase. Your experiences may vary!
These skip.(surefire|failsafe).tests
properties should probably be integrated into surefire/failsafe code itself, but I'm not sure how much it would violate the "they're exactly the same plugin except for 1 tiny difference" ethos.
Best Answer
I recently implemented this: after some headaches and a lot of testing, I have a configuration that works beautifully.
As you can see, there are 6 distinct Jacoco executions to run the tests, merge the files and create an aggregate report. On top of the Jacoco config, you also need to configure Surefire and Failsafe to take an argument from Jacoco (Surefire runs the unit tests and Failsafe runs the integration tests).
All of the configuration that I used should be there, what you do with it is your design architecture to make it fit within your desired requirements. Personally, I recommend a look into what I exclude and include within surefire and failsafe if you are having issues with files not being read.