skip to Main Content

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
enter image description here

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
enter image description here

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


  1. Chosen as BEST ANSWER

    I've figured out the key is to set IncludeReferencedProjects enter image description here


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

    enter image description here

    Update:

    In Tools -> option -> Fine Code Coverage -> Run MSCodeCoverage: Set No

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search