Maven with Cobertura and findbugs - tests are running twice

1.1k views Asked by At

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.

2

There are 2 answers

0
Amar Deep Singh On

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.

2
Kraal On

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.