Integration test code coverage using jacoco and maven

I have a maven test project that is testing our dev code. These 2 are different maven projects. Test your dev project project via maven dependency. I want to measure the coverage of an integration test code with a dev project using jacoco and maven plugin. I used to do this with jacoco and sonar where the test code generates the jacoco.exec file and then I manually created a dev project going through jacoc.exec as an argument in jenkins and get the code coverage report. I was basically not looking for a 100% automatic way to do this. Have read a couple of articles that use jacoco with maven but they all use the same project.

Appreciate any help / pointer.

thank

+3


source to share


1 answer


The "dirty trick" is the accumulation of Jacoco coverage reports. Since you have different projects, there is no legal way to do this, as by design, maven projects should be built without direct dependency.

But in the real world, nothing is perfect:

  • You specify a JaCoco report file with a fixed path. By the way, you can do this relative to your Maven repository, which is a pretty clean approach.
  • You build your projects in 2 stages: the first phase will build all projects running all possible tests. Better to have separate JaCoco report files per unit and integration tests. But they must be the same between projects and projects that must be configured to accumulate reports.
  • By completing the second pass, you trigger the magic mvn sonar:sonar

    . This will bring you 2 sonar projects (as I understand you now have the same picture), but the coverage will be much more accurate. The key is the unified reports calculated in the previous step.


Here is a fairly complete illustration of this idea and many links to simpler projects. And here's another question that illustrates the idea.

Hope this helps. I do the same approach for my multi-module projects to get coverage for the "lower layer" modules when running tests for the "higher layer".

+3


source







All Articles