I am new to unit testing C# in Visual Studio. I want to get the coverage report but I don’t have Visual Studio Enterprise so I installed Fine Code Coverage. What I don’t understand is it seems like giving coverage of the test code being run, instead of the source code being tested on.
Here is an example. Let say I have the following solution
Class1.cs
namespace ClassLibrary1
{
public class Class1
{
public int Sum(int a, int b)
{
return a + b;
}
public int Product(int a, int b)
{
return a * b;
}
}
}
UnitTest1.cs
using ClassLibrary1;
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void SumIsCorrect()
{
var lib = new Class1();
Assert.AreEqual(lib.Sum(1,2), 3);
}
}
}
When I run the test, Fine Code Coverage shows the following
Isn’t a coverage report suppose to tell me how many of the source code have been tested? If it just tells me how many test code has been run, isn’t it always 100% if I run all tests? Am I missing some configuration or is my understanding of coverage wrong?
2
Answers
I've figured out the key is to set
IncludeReferencedProjects
This is the screenshot from Visual Studio Enterprise.
There is nothing wrong with your understanding, and the Fine Code Coverage ‘s results is correct, except that the code coverage of Project Class1 is not displayed.
I am not familiar with Fine Code Coverage. You may need to report Fine Code Coverage issues on GitHub or use an alternative product.
Update:
In Tools -> option -> Fine Code Coverage -> Run MSCodeCoverage: Set No