12
votes

I have enabled the code coverage in the build definition for a project in TFS. enter image description here

It's building as expected, unit tests are running as well but code coverage shows "No build coverage data available" see the screenshot below.

enter image description here

Any help is appreciated.

3
Sorry if this is a silly question to you. But you did not mention your licence version. As I understood it MS Code Coverage is only available for Enterprise Version of VS/TFS. I always found it very confusing that the feature can be ticked on, but shows no results in the Professional Version.Robert K
@RobertK thank you for the feedback. Our TFS version says "Team Foundation Server 2015". I don't think we have the enterprise edition of the TFS.mahfuz01
I think there is no prof/enterprise flavor on TFS. But it would need at least one enterprise edition of Visual Studio on its build agent. To overcome this I am using the open source alternative OpenCover. And I wrote a small 'learning project' to integrate this with TFS 2015. If you are interested give it a try and/or join me there ;-): github.com/RobertK66/vsts-opencoverRobert K
@RobertK, Thank you very much for the offer. I will give it a go as soon as i have some spare time. :-)mahfuz01
@mahfuz01 - I have the exact same problem. Have you found a solution yet?Igor

3 Answers

7
votes

The coverage result is just a file with *.coverage extension.

So enabling Code Coverage Enabled checkbox is not enough. This checkbox enables calculating of code coverage and producing this file.

However to attach this *.coverage file to a build, you also need to enable Upload Test Attachments checkbox under Reporting Options section. Please see the image attached.

Reporting Options: Upload Test Attachments This checkbox enables exactly what you need, it will publish coverage result against with the build.

And the final log should look something like this:

2016-10-17T15:47:03.6834453Z Attachments:
2016-10-17T15:47:03.6834453Z   TFSBUILD 2016-10-17 11_46_53.coverage 
2016-10-17T15:47:03.6834453Z Total tests: Passed: Failed: Skipped:
2016-10-17T15:47:03.6834453Z Test Run Successful.
5
votes

Just test on my side, Code Coverage is available as expected. I'd like to share my steps for your reference:

  1. Create a default Visual Studio template.

  2. Specify the Solution in Visual Studio Build task, and check the Code Coverage Enabled in Visual Studio Test task. See the screenshots below:

enter image description here

enter image description here

Other settings are not changed.

  1. Queue build, then I can see the Code Coverage shows on build summary:

enter image description here

By the way, I'm using TFS 2015 Update2.

0
votes

The problem can be solved by checking two check boxing as shown in the picture only enabling Code Coverage is not enough you need to check Upload test attachments as well in the Test Template.

enter image description here