Enabling code coverage on TFS 2012—it’s easy

I’m so used to editing test settings to enable code coverage in TFS, that I was surprised how easy it is in TFS 2012.

First, inside Visual Studio 2012, code coverage is enabled by default. Those settings go with the unit test explorer, so they rely more on the “runsettings” file—if you even have one. If you want to customize that, check out this post.

For the build, first edit the build definition, and go to the “process” tab:

image

When you click on the ellipsis (“…”) next to “Automated Tests”, you’ll get this editor:

image

Click on the “Edit” button and you’ll get the following dialog:

image

Under “Options”, choose “Enable Code Coverage”. You may also want to fail the build if your unit tests fail. Keep clicking “OK” all the way out of the dialogs that were opened, and save your build definition.

Comments

  • Anonymous
    October 24, 2012
    The comment has been removed

  • Anonymous
    November 01, 2012
    Since I'm still getting the old Add/Edit Test dialog (without the ability to set code coverage) in VS2010 after upgrading TFS to 2012, I am assuming that enabling Code Coverage in TFS 2012 still requires the VS IDE to be installed on a build server. True?

  • Anonymous
    April 30, 2013
    Any answer to this? I've got to migrate an existing build system to TFS that previously used nCover, and without any kind of documentation on how to do this on a server, I am kind of dead-in-the-water. My company has licenses for VS.Net Pro only, so it is VERY important to know specifically what is needed for this functionality without diving in blind. It would also help to know if we need a license for VS.Net (which version???) to go on a server (a truly non-ideal solution, since IT likes to minimize the apps that get installed on our servers)

  • Anonymous
    June 17, 2013
    FYI, I went through the trouble of scheduling the TFS server to be unused for a time so I could install VS as the error message said (installed Pro because, well, the message just said simply "Install Visual Studio"). Queued up a new build after rebooting the server, and went to the code coverage section, where I found..."Code coverage is enabled for the test run. Install Visual Studio on the following build machine to get code coverage results: <ServerName>". I really dispute the central notion of this post that CC is "easy" in 2012. It's been nothing but a hassle, from spending hours searching and experimenting with an upgraded build only to find that the updated build template didn't support CC (had to change the template), to reading that CC is separated out of VS so that TFS could use it (which isn't true), and now to going through the trouble of installing a dev IDE on a server only to still get an error message, presumably neither because the error, blog post, nor MS forum "answer" from John Qaio actually specify which edition of VS is required. This is a lot of wasted time that could have been eliminated simply by MS being specific in any one of these places. Not a good experience from my standpoint.

  • Anonymous
    August 20, 2014
    totally agree with keith. I have 2013 ultimate installed on the bulid agent, and I still get the warning to install visual studio. yippee for no documentation Microsoft.

  • Anonymous
    February 12, 2015
    Thanks so much Darren! Saved my Bacon!

  • Anonymous
    February 18, 2015
    msdn.microsoft.com/.../ms253138%28v=vs.110%29.aspx