1

So I have Jenkins with the Cobertura plugin installed. I have Cobertura and findbugs in the POM and my tests are running twice...

I assume that this is because Cobertura instruments the bytecode and this causes the tests to re-run, which isn't a bad thing I guess, since the instrumented isn't the same as non-instrumented code...but I would really like the tests to be run only once.

I have tried running them locally on commandline using these commands:

mvn cobertura:cobertura -Dcobertura.report.format=xml

mvn findbugs:findbugs -Dfindbugs.onlyAnalyze=true

mvn cobertura:cobertura -Dcobertura.report.format=xml findbugs:findbugs -Dfindbugs.onlyAnalyze=true

but I can't get the tests to run twice locally, where as on Jenkins the are running twice. I am not sure why this is happening and whether I could make it stop.

I am using Cobertura to generate reports for me...I assume that to generate them it needs to re-run the tests? But it doesn't make sense since they are already being run once.

user2405469
  • 1,953
  • 2
  • 22
  • 43
  • possible duplicate of [running junits and cobertura with maven](http://stackoverflow.com/questions/732995/running-junits-and-cobertura-with-maven) – Artjom B. Sep 21 '15 at 21:25
  • not a duplicate as the question and answer you're referring to is more than 6 years old and is obsolete. – Kraal Sep 22 '15 at 12:18

2 Answers2

3

We have faced the same behavior. It seems to be default behavior of Cobertura to rerun test cases for calculating coverage.

We switched to JaCoCo tool, which proved to be better . It does not re-run the test cases for coverage report.

1

Indeed you have to run tests twice with cobertura-maven-plugin (or use different profiles). This behavior is due to the fact that it runs Cobertura instrumentation in its own lifecycle and uses Cobertura executable instead of Cobertura API.

If you want to generate a Cobertura report while only running your tests once, you can give a try to the qualinsight-mojo-cobertura-core plugin. This plugin uses a different approach to run Cobertura instrumentation.

You'll find a documentation on the project's page: https://github.com/QualInsight/qualinsight-mojo-cobertura .

Note that this plugin has still some limitations, but it may be a viable alternative in your context.

Hope it helps !

Regards.

Kraal
  • 2,779
  • 1
  • 19
  • 36
  • Please don't post the exact same answer to multiple questions. Instead select the best question and post your answer there, then you can flag the worse questions as duplicates of the better one. If they are not duplicates then you need to change each answer so that it answers *that specific question*. I voted to close this question as a duplicate of the original question: [running junits and cobertura with maven](http://stackoverflow.com/questions/732995/running-junits-and-cobertura-with-maven). – Artjom B. Sep 21 '15 at 21:34
  • 1
    I get your point, however this question was asked 3 months ago, the one you're marking as the "better question" was asked 6 years ago and was tagged with "maven-2", "ant". I think you'll agree that an answer given more than 6 years ago may be obsolete isn't it ? Therefor I don't agree with your vote (note that I'll modify my other answers to refer to this question which is the most recent one.) Kind regards. – Kraal Sep 22 '15 at 12:10