简体   繁体   中英

ReSharper dotcover showing 0% coverage despite tests running through code

I'm assuming this is an error on my part but I can't figure out why ReSharper dotcover is showing my test coverage of certain queries (and commands too) as 0%.

So I have a .NET Core CQRS API that is made up of a lot of EF Core LINQ. Below is a simple example of one of my queries's main execute method (I left out the DI constructor but I'm sure you git the idea):

public bool Execute(SelectIsReportRequested query)
{
     var context = _clientDatabase.GetContext(query.DatabaseId);

     var result = (from a in context.Assessments
                   join r in context.Registrations on a.AssessmentId equals r.AssessmentId
                   where a.PublicId == query.ResponseId
                   select r.ReportRequested).SingleOrDefault();

     return result == 1;
}

Then I have the following test that mocks the various bits and runs the query:

[TestMethod]
public void It_should_return_true_if_a_report_has_been_requested_for_the_givenassessment()
{
    const int assessmentId = 1;
    var responseId = Guid.NewGuid();
    var mockRepository = new Mock<ICViewClientContext>();

    var assessments = new List<Assessments>
    {
        new Assessments { AssessmentId = assessmentId, PublicId = responseId },
    };
     var registrations = new List<Registrations>
     {
        new Registrations { AssessmentId = assessmentId, ReportRequested = 1 },
     };

     mockRepository.Setup(x => x.Registrations).Returns(registrations.AsDbSetMock().Object);
     mockRepository.Setup(x => x.Assessments).Returns(assessments.AsDbSetMock().Object);

     var mockClientDatabase = new Mock<IClientDatabase>();
     mockClientDatabase.Setup(x => x.GetContext(1)).Returns(mockRepository.Object);

     var query = new Queries.Assessments.SelectIsReportRequested(2, responseId);
     var handler = new Queries.Assessments.SelectIsReportRequestedHandler(mockClientDatabase.Object);
     var result = handler.Execute(query);

     Assert.AreEqual(true, result);
 }

The tests passes (and will also fail if I break the logic in the LINQ) or any other logic in the code.

However, running dotcover runs the test, passes it but says that none of it is covered.

I would love to know why because it's really driving me insane and worries me that I've done something completely wrong!

So I think through blind luck I have been able to solve my issue and wanted to post what I did just in case it helps anyone else.

Whilst trying to get the logs to submit to JetBrains I did the following:

  1. In ReSharper | Options… | dotCover | General, disabled 'Use preloaded Unit Test runners'
  2. Saved settings
  3. Went back and enabled 'Use preloaded Unit Test runners'
  4. Saved settings

Then I re-ran dotcover and suddenly all my test coverage was shown and all my test cover code highlighting was shown correctly.

I've sent a message back to JetBrains and if they give me any info as to why that solved it I'll post that too.

I had a similar issue when dotCover didn't recognize some of the unit tests.

I was able to resolve it by removing Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll from Test Project references and installing MSTest.TestFramework and MSTest.TestAdapter nuget packages.

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