I'm running unit tests in my VSTS build (although I get the same results running locally in Visual Studio). I'm using a .runsettings file to set assemblies to ignore etc and this linking into both the Visual Studio project and is set in the VSTS test task.
I have checked "Code Coverage enabled" in the VsTest task, the tests run through and coverage is published in VSTS for example is:
When I download the .coverage file and open in Visual Studio, these figures match up (as it does if I actually run the tests in Visual Studio locally). Here's the output:
The problem I'm having is when I then export this .coverage file to xml (as I need to process these figures as part of the build), I'm using the following command to do this:
"C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe" analyze /output:out.xml "TST-20180307.7.debug.any cpu.1368.coverage"
However, when I do, the total blocks covered & total in the exported xml file do not match those from the .coverage source:
<module name="vstsrestapicommon.dll" path="vstsrestapicommon.dll" id="xxx" block_coverage="95.49" line_coverage="90.85" blocks_covered="678" blocks_not_covered="32" lines_covered="268" lines_partially_covered="1" lines_not_covered="26">
So basically we're looking at a single module (dll) but Visual Studio and VSTS both report blocks covered as being 641 but the exported xml reports the same as 679.