Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code coverage for a class library using dotCover

I have a simple class library that gets tested with MSTest using VS 2010.

I installed the trial version of dotCover 1.2. with no ReSharper installed.

VS only has the menu items "Cover Startup Project" and "Cover Application". They open boxes where I can open all kinds of applications but no class library.

Is it not possible to calculate code coverage for a class library without another application that uses it?

like image 563
Mathias F Avatar asked Apr 21 '12 18:04

Mathias F


People also ask

How do I generate a code coverage report in Visual Studio?

On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.


1 Answers

In my case I have a solution containing a class library, and another solution containing the unit tests.

I wanted to see how much of the class library my unit tests covered. After running Cover Unit Tests from the Solution context menu Dotcover by default shows me the coverage of the methods in the test classes themselves. To see the coverage of the class library you need to unselect Match coverage results with current project structure:

enter image description here

Note that this will only cover class library projects referenced in the tests. If you have a project that doesn't have any tests at all then that project won't show as a symbol in the Coverage Tree.

Thanks to this answer for pointing me in the right direction.

like image 70
Matthew Lock Avatar answered Sep 21 '22 19:09

Matthew Lock