TFS 2013 - No Code Coverage Results

2019-01-17 02:51发布

问题:

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!

回答1:

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!



回答2:

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



回答3:

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)".



回答4:

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.



回答5:

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.