dotcover showing 0% coverage despite tests running through code


I logged this on SO here ( but no one has answered yet

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:

    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!

Comment actions Permalink

So unbelievably the problem has now gone away! I think it might have been when I was trying to get the logs and unchecked 'use preloaded unit test runners'. I then saved it...thought twice about it...went back and re-checked it and saved it again. And through this fumbling I seem to have fixed it! Does that sound like it might have solve some weird error? I had been experiencing the issue for over a month so I know it wasn't just a one time thing.

Comment actions Permalink

Hi Ben,

Great to hear that now it works fine for you!
I could hardly see any connection between 'use preloaded unit test runners' setting and the problem. The only thing that comes to my mind is that somehow ReSharper settings were corrupted on your machine and after these manipulations, they came into the normal state.

Comment actions Permalink

I had the same problem. Zero test coverage showing. Disable and re-enable that setting (based on what you're saying, possibly any setting) and it works. 


Please sign in to leave a comment.