0
votes

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:

VSTS Code Coverage

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:

Visual Studio Code Coverage

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.

1

1 Answers

0
votes

debug | any cpu | Blocks | 77.51% | 417/538

This is the total code coverage result.

<module name="xxx.dll" path="xxx.dll" id="xxx" block_coverage="78.21" line_coverage="86.32" blocks_covered="445" blocks_not_covered="124" lines_covered="164" lines_partially_covered="2" lines_not_covered="24">

This is just an assembly’s code coverage result.

For example:

enter image description here

The total covered result is 57.69%, but the classlibrary1.dll’s covered result is 31.25%, so the exported xml file’s result is block_coverage="31.25" for classlibrary1.dll.