7

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:

enter image description here

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:

enter image description here

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

enter image description here

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?

Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80
Rikai no hōhō
  • 737
  • 1
  • 7
  • 13
  • Works for me using dotnet core 3.1 and default ClassLibrary and MSTest project templates in Visual Studio (VS2019 16.5.4 and Resharper 2020.1). I get one warning on the 'Unit Test Sessions' window (MSTest adapter uses .NETcore 1.0). You seem to have 2 warnings, maybe the other warning is stopping it from working. Also try clicking on the 'tests' link on the 'Unit Test Coverage' window. – Piers Myers Apr 28 '20 at 12:57
  • Could you please open a new issue in dotCover bug tracker: https://youtrack.jetbrains.com/issues/DCVR? In order to answer the question, dotCover log files are required. Start VS with the following command line keys: /ReSharper.LogLevel Verbose /ReSharper.LogFile. You will find log files in %Temp%\JetLogs folder. Please attach log files to the issue. – Ekaterina Solovova Apr 28 '20 at 13:30
  • @PiersMyers You're right, I've got two warnings. I believe the first one should be similar to yours. The second one is more concerning. It says "Coverage analysis: Profiler message: API was requested, but wasn't called (C:\Users\user\.nuget\packages\microsoft.testplatform.testhost\16.6.1\build\netcoreapp2.1\x86\testhost.x86.exe [pid=11276])" – Rikai no hōhō Apr 29 '20 at 18:36
  • @EkaterinaSolovova I will do as you are instructing. Thank you. – Rikai no hōhō Apr 29 '20 at 18:36

1 Answers1

0

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.