Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

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

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.

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top