Mar 17 2008

Code coverage not available when debugging unit tests

Category: .NetRory Primrose @ 03:54

Yep, this one bit me last week.

I had been writing some unit tests and debugging them. When the tests were finished, I kept wanting to look at the code coverage. All I would see was the message "Code coverage is not enabled for this test run". After trying lots of things and wasting 30 minutes, it turns out that code coverage is not available when debugging unit tests, even though code coverage is enabled through the testrunconfig file and that the build configuration is set Debug.

To avoid this mistake in the future, you can enable a warning message that specifically highlights the problem. Go to Tools, Options, expand the Test Tools node and select Default Dialog Box Action. There is an option called "When starting a remote test run or a run with code coverage under the debugger:". Set this value to "Always prompt". The next time that you run a unit test with the debugger attached, you will get a warning message saying "Debugging tests running on a remote computer or with code coverage enabled is not supported. The tests will run under the debugger locally and without code coverage enabled.".

No more confusion.

Tags:

Comments

1.
Gerardo Contijoch Gerardo Contijoch Argentina says:

Thank you very much!
I wasted a lot of time trying to figure this out!
It's a disaster the way Microsoft implemented Code Coverage in VS.
Why isn't there an option in the Run Tests button that enables code coverage for only a test run?
A button enabling/disabling CC in the Test Results windows would be helpful too...

2.
arachnode.net arachnode.net United States says:

Thank you for this tip.  Solved my problem...

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading