Why is code coverage not working in ReSharper?
Asked Answered
P

1

10

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?

Pennon answered 27/4, 2020 at 19:59 Comment(5)
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.Abukir
Could you please open a new issue in dotCover bug tracker: 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.Commination
@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])"Lachrymator
@EkaterinaSolovova I will do as you are instructing. Thank you.Lachrymator
When ReSharper starts doing this I find that the best thing is to say delete all coverage data (from the code coverage window), then rebuild, then run all tests in solution, then cover all tests in solutionUnderhill
A
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.

Aucoin answered 26/8, 2020 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.