Reputation: 66584
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:
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
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):
(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
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
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
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
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