-->

Is there anyway to merge cobertura coverage xml re

2019-04-06 15:21发布

问题:

I have c++/c application with a lots of unit tests. I would like to get overall coverage and also individual coverage of each test with condition that each test can be run only once. Format of coverage must be xml (cobertura xml) for jenkins cobertura plugin to process.

So far I generate gcno files upon compilation and gcda files when source is used. Then call gcovr to get xml file.

I would like to create coverage of each unit test (thus creating coverage xml for every unit test) and then merge these xml files into one xml file.

Thanks!

回答1:

The last pre-release (4.0.0-rc4) of ReportGenerator can merge cobertura files.

You can install it from nuget

usage:

reportgenerator "-reports:target\*\*.xml" "-targetdir:C:\report" -reporttypes:Cobertura

A file Corbertura.xml is generated in the targetdir directory

You can use the dotnet core version to use it on linux or mac



回答2:

Sorry can't comment:

@x3mspeedy was nice enough to post a script, but they have moved the script around a bit since then, I searched the repo and pulled it into a public gist here:

https://gist.github.com/tgsoverly/ef975d5b430fbce1eb33



回答3:

I wrote python script which can merge cobertura reports together. It only merges line "hits" and is able to filter specific packages while merging.

Conditional(branch-rate) coverage and line coverage (line-rate) percentage values are not merged yet. Jenkins plugin recalculates these values so in this context it doesn't have to be implemented (but maybe it will).

Also conditional coverage can't seem to be put together easily, so it doesn't work when reports cooperate on final value (meaning one file has condition-coverage 50% (2/4) and other also condition-coverage 50% (2/4) other two branches. Result is set to be higher of these two numbers so it will be still 50% (2/4)



回答4:

Cannot add comments so see :

https://github.com/cobertura/cobertura/wiki/Command-Line-Reference

on the bottom.



回答5:

I was looking at solution as well, but in my case there was about 1000 of Cobertura XML files and all above scripts were really slow in processing such amount.

In the end I've come up with merge-cobertura.py a Python script which does the merge. However it's quite limited in what it supports as all I needed was to merge reports from OpenCppCoverage to be used at Codecov. So it just merges line hits ignoring any branch information (there is none coming from OpenCppCoverage) and assuming all coverage reports are for same path. It also merges all packages into one.

Maybe somebody will find this useful as well, there are some more details in my blog.



回答6:

For what it's worth, I made a node script to merge multiple cobertura XML reports. Set up is quite straightforward and it fits my needs. https://gist.github.com/merlosy/8efabc754985aa6e754a3d5932b1a77d