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:


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


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


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 (7)

  1. Jaans says:

    I'm getting the following message from TFS Build 2012 – Do we really have to still install VS on the build computers?

    Code coverage is enabled for the test run. Install Visual Studio on the following build machine to get code coverage results: XXXX

  2. Keith says:

    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?

  3. Keith says:

    *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)

  4. Keith says:

    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.

  5. steve says:

    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.

  6. Tyler says:

    Thanks so much Darren! Saved my Bacon!