35

I have a TFS 2013 environment setup and I am trying to get TFSBuild to gather my code coverage results after a build.
The tests are running fine, but no matter what I try, I get a message saying "No Code Coverage Results".

I have read about a "Code Coverage Analysis Service", but that is not installed on my servers at all and I can't seem to find it anywhere.

I have gone through the process of the builds to make sure I have the "Automated Tests --> Test Source --> Run settings --> Type of run settings" set to CodeCoverageEnabled, but no matter what else I try, I can't get the results to get published to the Analysis services database so I can run the Code Coverage Reports.

I have tried a run settings file, but with no luck, so I have taken that out of the equation.

Any help would be greatly appreciated!

Nahuel Ianni
  • 3,177
  • 4
  • 23
  • 30
tcmg.digiorgio
  • 351
  • 1
  • 3
  • 4

5 Answers5

56

I just figured out what the problem was that my Code Coverage weren't been calculated on the buildserver. I figured this out with the helpdesk of Microsoft and it is a small UI bug.

Steps to reproduce: Create a new build definition.

  1. Go to the process tab of the build definition and select the solution file to build.
  2. Now expand the "Automated tests" section and expand the "Test Source".
  3. Expand the "Run settings" and change the "Type of run settings" from "Default" to "CodeCoverageEnabled".
  4. Save the builddefinition and run your build.
  5. Examine build results and notice no code coverage is calculated.

To fix this issue use the other ui of the build definition.

  1. Select the "Automated tests" node.
  2. Now in that row on the right you will see a button with "...". Hit it and a dialog will be opened.
  3. Hit "Edit" to edit your test source. You will see that Code coverage is enabled. If not select it.
  4. Hit Ok and Ok again to close the two dialogs.
  5. Now save the build definition and run your build again.

Now the code coverage does get calculated!!! The microsoft helpdesk has submitted a bug to the development team and it will be fixed I guess the next release. Small bug but it cost me more then two days to find the bug!

NGaida
  • 688
  • 3
  • 10
LockTar
  • 5,364
  • 3
  • 46
  • 72
  • 5
    Damn! As hard as I try, I can only up vote this once! – Jeff Sheldon Jul 26 '14 at 01:37
  • Your welcome. I don't think that the fix will be released with Update 3 because Update 3 is already in Release Candidate version. Hopefully it is fixed in Update 4. The Microsoft helpdesk ensured me he would contact the Development team because now he could reproduce the "small" bug. I'm glad I could help you! – LockTar Jul 27 '14 at 15:55
  • Ralph, I'm a little confused about the "other ui of the build definition". What other ui are you referring to? I have VS Premium installed on the build server and still can't get this working as expected. Thanks for all your help, I appreciate it. – tcmg.digiorgio Jul 29 '14 at 13:00
  • 1
    Hi. You have a sort of two UIs when your editing a build definition. On the process tab of your build definition you see the white property area where you can set everything. But you can also set the "Automated tests" section with a different editor. With a different editor I mean a popup window that you can open with the "..." button on the right of the "Automated tests" row. Select that row first to see the button. If you change the settings in the popup and then save it in the popup (hit OK), the settings are adjusted in the white property area. Hopefully this will be clear for you... – LockTar Jul 29 '14 at 14:23
  • I want to add that I was having this issue too, however I wanted to specify a UserDefined runsettings file as the defaults include everything. I followed the steps above and then after successfully getting coverage with the CodeCoverageEnabled flag I then set a UserDefined runsettings file in the Process tab of the build definition and this finally got coverage enabled that honoured the runsettings file. – satnhak Jan 05 '15 at 23:13
  • 1
    Just had the same problem on Update 4 (fix still works) – PeterI May 07 '15 at 14:32
  • I think they won't fix it. Maybe with Update 5 but I don't think so. I think they will focus on the new build definition editing for TFS 2015 in the browser. – LockTar May 08 '15 at 13:38
  • Can't get it to work. I still have "no code coverage results" on build summary. VS2013 Ultimate Update 4. – ken2k Jun 18 '15 at 10:01
  • 1
    Well, this must work. A lot of user got it to work. Send me a PM and I will try to help you. – LockTar Jun 18 '15 at 10:56
  • 2
    @ken2k (and others having trouble) [here's a screenshot](http://i.imgur.com/9e1XNy4.png) of the editor in question which is able to enable code coverage. Kudos to Ralph for publishing this workaround! – David Peters Nov 04 '15 at 22:36
  • Apart from above suggestion I had to follow what's specified in this post http://stackoverflow.com/questions/27836882/code-coverage-in-vs2013-show-coverage-of-test-and-not-actual-code?rq=1 – tangokhi Mar 17 '16 at 08:03
  • TFS 2017 & VS2017 Enterprise and this issue/fix still holds true. – Always Learning Nov 11 '17 at 01:44
  • Don't forget that XAML builds are already deprecated for a while. In TFS 2018 this isn't supported anymore! – LockTar Nov 15 '17 at 09:32
4

Do you have a Premium or ultimate visual studio installed on your build machine? Either of those is required to get code coverage results back to TFS

Just TFS
  • 4,697
  • 1
  • 18
  • 22
0

I think the "other window" is referring to right-clicking on the Solution's "Local.testsettings" file (or other [ ].testsettings files), selecting "Open" and navigating through the various setups. When you set the "Test Run location" radio button to "Run tests using local computer or a test controller", there is a setting under "Data and Diagnostics" for "Code Coverage (Visual Studio 2010)".

0

I am using local build server with Visual Studio online with a .runsettings file and I had exactly the same issue.

None of the trickery above helped, so I tested the build script on the hosted build controller and it worked fine, so I decided the problem must be the build server itself.

I changed the Build Service account from "Network Service" to a regular windows user account in the TFS Configuration Tool and now code coverage is collected. Note that this user will need access to the TFS build directories.

j0ffe
  • 621
  • 8
  • 13
0

The above workarounds didn't work from me (VS2015 update5 & TFS2013 Update 3).

In my case, Visual Studio was not installed on the build server which is a requirement it seems for code coverage results to be returned.

From MSDN

Microsoft Visual Studio is required to be installed on the build server for the following scenarios:

  • To build any CPP test project, you must install Visual Studio Professional or later.
  • To run unit tests, or coded UI tests, you must install Visual Studio Professional or later.
  • To use data and diagnostic data adapters:

     - Code coverage: Visual Studio Premium or later.   
     - Test impact: Visual    Studio Ultimate.  
     - IntelliTrace: Visual Studio Ultimate.
    
  • To build any modern style apps on a build machine: Visual Studio Ultimate or Visual Studio Express for Windows 8 (Operating system on build server must be Windows 8).

  • To compile and run tests for a project with a faked assembly: Visual Studio Ultimate.
DomBat
  • 1,981
  • 5
  • 27
  • 42