-
Notifications
You must be signed in to change notification settings - Fork 386
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
Coverage is not calculated if there is rabbitmq used #506
Comments
I cannot repro, I mean if I start test startup code run and I don't have correct rabbit configuration and get exceptions. How you run in "mock" mode?
Can you also try to enable logging to undestand what is instrumented? https://github.com/tonerdo/coverlet/blob/master/Documentation/Troubleshooting.md#msbuild-integration |
hey @MarcoRossignoli thanks for trying. You need a real rabbit server and change the configuration file properly. I've masked my settings, so you get error. |
Ok so your tests run mocked by |
Sorry for providing a nonworking sample. But you need a working rabbit to run my sample. I can fake/mock rabbit server by using its InMemory feature, with the following code: public class TestWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup : class
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureTestServices(services =>
{
services.AddSingleton(provider => Bus.Factory.CreateUsingInMemory(configure =>
{
configure.ReceiveEndpoint("testendpoint", endpoint =>
{
endpoint.Consumer<MessageConsumer>(provider);
EndpointConvention.Map<SendMessageEvent>(endpoint.InputAddress);
});
}));
services.AddSingleton<IHostedService, MessageMassTransitService>();
});
}
} And it works perfectly fine. I mean, the coverage is calculated. But If I don't use fake/mock of the rabbit. I mean, if I access the real rabbitmq server from the running test environment, the coverage results are not calculated. With the conditional statement in my test, I have tried to demonstrate the difference. If the condition is true, my code uses inmemory rabbit, and coverage is calculated. |
I have tried with the global tool, unfortunately, the result is the same. I've also run the tests with the following command: I've set isRabbitFake = true But when I set it to false Interesting thing here is, "GenerateCoverageResult" step is missing with the tests running on real RabbitServer, |
Dup of #573 (comment) |
First of all, thanks a lot for this great tool.
I am testing my REST Api by following Microsofts this guide: https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.2
In this guide, I am extending dotnet.core's WebApplicationFactory:
My sample repo is here: https://github.com/fkucuk/shared/tree/master/CoverletCoverageIssue
In the startup of my application I configure RabbitMQ. On the test project I can override this configuration. If I don't, its own configuration is used.
The interesting thing here is, while testing if I don't override the setting in the Startup.cs the coverage report is as follows.
In this execution, dotnet uses the appsettings.Development.json file on the api project, and connects the real rabbitmq server.
But if I override the rabbit config and use fake of the rabbit, in memory, coverage works perfectly fine:
Accessing an outer environment, interestingly, interrupts calculation of coverage.
I know, when testing I have to fake or mock real systems. But I am scared if any other behavior may cause coverlet coverage calculation to fail.
What I am trying to ask here is, is this the expected behavior?
The text was updated successfully, but these errors were encountered: