简体   繁体   中英

Why is code coverage not working in ReSharper?

I have installed JetBrains' DotCover and ReSharper installed in Visual Studio 2019.

Unfortunatelly the DotCover code coverage seems to be not working. I have this sample class: using System;

namespace ClassLibrary1
{
    public class Class1
    {
        public int X { get; set; }
        public int Y { get; set; }
        public int Division()
        {
            return X / Y;
        }
    }
}

And this sample unit test:

using ClassLibrary1;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            var c = new Class1 {X = 10, Y = 2};
            var d = c.Division();
            Assert.AreEqual(d, 5);
        }
    }
}

Then in ReSharper's "Unit Test Sessions" window, I select "Cover Unit Tests" as shown below:

在此处输入图像描述

This action runs my tests and when I move to ReSharper's "Unit Test Coverage" window, I see all coverage percentages as 0% and a warning message stating "Coverage info for some tests is absent or outdated", as shown below:

在此处输入图像描述

Also, in the Visual Studio code editor window, all the statements in my class are marked as "Statement uncovered" as shown below:

在此处输入图像描述

So, for some reason dotCover seems to be not working. I tried dropping the coverage data and running the tests again, but the result is the same.

What am I missing?

I just ran into something similar. In my case, I had just added a test using MSTest instead of MSTestV2 for my unit tests and code coverage stopped working. I switched to MSTestV2 by adding the following nuget packages:

MSTest.TestAdapter (v2.1.2)

and

MSTest.TestFramework (v2.1.2)

and removing the project reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.

Hopefully this helps someone!

Also, I'm on Visual Studio 2017 Professional 15.9.26 and dotCover 2020.2 if that makes a difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM