Timwi
Timwi

Reputation: 66584

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?

Upvotes: 11

Views: 6826

Answers (5)

Marc Gravell
Marc Gravell

Reputation: 1063328

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

Upvotes: 3

Abyx
Abyx

Reputation: 12918

In my case, when I challenged this problem, I had "no test run configuration available" under Test->Select Active Test Run Configuration menu.
I removed/added .testrunconfig file, and the code coverage came back.
(VS2005 Team Edition)

Upvotes: 0

Stephen M. Redd
Stephen M. Redd

Reputation: 5428

Be sure to run your tests from the Test View or Test List window... not from the test results window. Re-running tests from within the test results window doesn't always honor your test run configuration settings.

Upvotes: 0

Paul Whitehurst
Paul Whitehurst

Reputation: 579

If this is for a c++ project, ensure that you have Profiling enabled. Bring up your project properties -> Linking -> Advanced. Find Profile and set it to Enable Profiling information (/PROFILE).

Upvotes: 0

Asrail
Asrail

Reputation: 146

Take a look at this page and see if that helps: Tips on Using Code Coverage in Visual Studio 2005

He had an issue even after setting the configuration file you mentioned and the issue was related with assemblies located on GAC.

Upvotes: 2

Related Questions