-
Notifications
You must be signed in to change notification settings - Fork 389
Coverage incorrectly reported as 0% for integration tests #1461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @TheMagnificent11. I'm not the developer of Coverlet, but I faced with the same issue while worked with WebApplicationFactory. The root cause in my case of missing coverage results was OneTimeTearDown method (global one), which disposed WebApplicationFactory and their http client. A solution for us was just to remove disposing of them from OneTimeTearDown =) |
I implemented Also, each of my tests creates and disposes of the HTTP client. All the tests use the following method to make HTTP requests. protected async Task<HttpResponseMessage> HttpRequest(HttpMethod method, string apiPath)
{
using (var request = new HttpRequestMessage(method, apiPath))
using (var httpClient = this.factory.CreateClient())
{
return await httpClient.SendAsync(request);
}
} However, I still get 0% coverage for my integration tests 🤷 I'm going to remove my I wonder if my issue has anything to do with the fact that I'm implementing Are you using |
#901 seems to be related/duplicate of this issue |
I created a more minimum implementation of integration test using
So I'm not sure why the coverage does work in project from my original comment 🤷 |
Can you try to take a log and verify that all expected dll are instrumented? https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/Troubleshooting.md#collectors-integration |
@MarcoRossignoli here's my run settings file. <?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura</Format>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
<InProcDataCollectionRunSettings>
<InProcDataCollectors>
<InProcDataCollector
assemblyQualifiedName="Coverlet.Collector.DataCollection.CoverletInProcDataCollector, coverlet.collector, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null"
friendlyName="XPlat Code Coverage"
enabled="True"
codebase="coverlet.collector.dll" />
</InProcDataCollectors>
</InProcDataCollectionRunSettings>
</RunSettings> And here are the logs. log.datacollector.23-03-31_21-18-58_26559_1.txt Thanks |
You don't need to set the |
@MarcoRossignoli I updated the settings and ran it again. Here's the updated settings. <?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura</Format>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings> Here are the new logs. log.txt |
@MarcoRossignoli I've created a repository with a more minimal replication of the issue. The My hypothesis is that using an implementation of Here are the logs I got on my laptop. log.datacollector.23-04-01_15-39-28_26818_1.txt |
@MarcoRossignoli was that repository that contained more minimal replication of my issue useful? |
I didn't have time to check yet, I'm pretty busy this period. let's see if @daveMueller @petli has got some fresh ideas. |
I feel rather embarrassed. The tests that were supposed to contribute to coverage (in both my original repository and the experiment repository) were using BDDfy, but I wasn't adding the The super-fast speed of execution of the tests should have been a tell-tale sign. I made the appropriate changes in my experiment repository and the coverage looked correct. Sorry about the hassle. |
I have a open source project that is using Coverlet to calculate test coverage.
The coverage seems to work correctly for unit tests.
However, coverage doesn't get reported for integration tests.
The integration tests I'm running use
Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory
to bring up a ASP.Net Web API application in memory and then uses a HTTP client to make API calls to this in-memory application.However, none of the code executed is being included in the coverage. It doesn't even get the top-level controllers that get hit when the HTTP request is executed.
See this pull request for more details.
The
dotnet test
command is in the GitHub Action (dotnet test ./Lewee-CI.sln --configuration Release --no-build --collect "XPlat Code Coverage" --results-directory ./coverage
).The text was updated successfully, but these errors were encountered: