dotcover showing 0% coverage despite tests running through code Follow
I logged this on SO here (https://stackoverflow.com/questions/50283412/resharper-dotcover-showing-0-coverage-despite-tests-running-through-code) 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:
[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!
Please sign in to leave a comment.
Hi Ben,
Could you please collect dotCover log files? https://dotnettools-support.jetbrains.com/hc/en-us/articles/206545979-How-to-get-dotCover-logs
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.
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.
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.
Hi I have the same problem , dotCover doesn't work at all. i tried on projects .net 3.1 , .net 6 and .net 7 .
Im clicking this one
What I tried :
1. Delete cache from File/Invalidate Caches
2. Enable Highlighting form dotCover/Highlighting