简体   繁体   中英

Integration Test Code Coverage using jacoco and maven

I have a maven test project which tests our dev code. These 2 are different maven projects. Test project access dev project via maven dependency. I want to measure integration test code coverage against dev project using jacoco and maven plugin. Previously I have done it using jacoco and sonar where test code generates jacoco.exec file and then I manually built dev project passing jacoc.exec as arg in jenkins and get code coverage report. I was not basically looking for 100% automated way of doing this. Have read couple of articles which uses jacoco with maven but all those uses single project.

Appreciate any help/pointer.

Thanks

The 'dirty trick' here is to accumulate Jacoco coverage reports. As you have different projects there is no legal way to do this as by design maven projects are to be built without direct dependency.

But in real world nothing is ideal:

  • You point JaCoco report file with fixed path. By the way you can do it relatively to your Maven repository which is pretty clean approach.
  • You build your projects in 2 phases: first phase build all projects running all possible tests. It's better to have separate JaCoco report files per unit and integration tests. But they should be the same among projects and projects shall be configured to accumulate reports.
  • Doing second pass you run your mvn sonar:sonar magics. This will bring you 2 sonar projects (as I understand now you have the same picture) but coverage will be much more precise. The key is unified reports calculated on previous stage.

Here is complete enough illustration of this idea and lot of references to more simple projects. And here is another question which illustrates idea.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM