Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Visual Studio say "Code Coverage is not enabled for this test run" when it's enabled?

In Visual Studio, I just created a simple Unit Test to test a method I wrote. I wanted to check the code coverage, but the Code Coverage window only ever states that "Code Coverage is not enabled for this test run". Why? Note:

  1. I've already followed the instructions on this page, i.e. the test configuration does have the relevant assemblies checked on the Code Coverage options page.
  2. I've clicked "Run test", not "Debug test", which some sources claim causes this.
  3. I've tried running the test with the current build configuration set to either "Debug" or "Release"; neither works.
  4. I've also followed the suggestions on this page (re-select the testrunconfig file by selecting Test => Select Active Test Run Configuration), to no avail.

Yet I still get the message "Code Coverage is not enabled for this test run" every time I run the relevant test. How do I enable Code Coverage once and for all?

like image 268
Timwi Avatar asked Sep 11 '09 17:09

Timwi


1 Answers

I used to struggle with MSTest, in a lot of areas (including code-coverage) - frankly, it* doesn't exactly go out of its way to make life easy - especially with the extra testrunconfig etc duplicating a lot of things already in the csproj.

Anyway; than I found that TestDriven.NET has this built in (as long as you have the right edition of Visual Studio to include MSTest and coverage):

alt text
(source: mutantdesign.co.uk)

This will use your existing test framework (including MSTest), but it will jump through all the usual hoops to get test coverage enabled, without you needing to mess with the configuration. It even works with the source-code colorization (red/blue untested/tested etc). Handy.

*=the tool itself, and the GUI integration

like image 119
Marc Gravell Avatar answered Sep 18 '22 08:09

Marc Gravell