Unit Tests Coverage only shows coverage on the unit test itself.

I'm using Rider and I want to do analysis on the code coverage of my tests.

The problem is that the report generated only shows coverage on the unit tests itself instead of the code that it is testing.

E.g

class MyClass
{
void MethodToTest()
{
// whatever in here
}
}

[TestClass]
class MyUnitTest
{
[TestMethod]
public void MyTest()
{
var myClass = new MyClass();
myClass.MethodToTest();
}
}

Running coverage analysis using MyTest() will only generate a report on the coverage of MyTest(), not MethodToTest(). Anything that I missed? I'm using MSTest if it matters.

0
3 comments

Hello Adam Malik Yusof,

dotCover shows the coverage of all the executed statements with no means is it a test code or code under test. 

The provided example missing access modifiers. The below code works well:

    public class MyClass
    {
        public void MethodToTest()
        {
            // whatever in here
        }
    }

    [TestClass]
    public class MyUnitTest
    {
        [TestMethod]
        public void MyTest()
        {
            var myClass = new MyClass();
            myClass.MethodToTest();
        }
  }
0

Sorry for the late reply, I was on holiday.

That is what I understand and that's what the examples that I'm able to find also shows. But somehow when I execute, the report generated only shows the coverage for the unit tests codes (MyUnitTest class), none about the actual code itself (MyClass class). I'm not sure if I misconfigure something.

Also, thanks for pointing out the bad example. Writing out the example code out of my head tends to have such error but the actual code does have the public access modifier. 

0

Hi Adam Malik Yusof,

Perhaps the missing class is added to coverage filters in Rider settings: Build, Execution, Deployment | dotCover | Filtering?

If it is not the case, please clarify how the tests and the code under test relate to each other. Are they in the same project or different projects in one solution, or maybe it is two solutions, etc? 

If you create a brand-new solution with class library and a unit tests projects, does the coverage work fine?

0

Please sign in to leave a comment.