XunitContext icon indicating copy to clipboard operation
XunitContext copied to clipboard

ASP.NET integration testing leads to garbled logs

Open GeeWee opened this issue 4 years ago • 1 comments

Hello. Great, great project.

In ASP.NET Core (at least 5 and up), when integration testing with the WebApplicationFactory ExecutionContext is not preserved across calls to the TestServer.

This leads to some garbled log outputs that are super hard to debug. Because any log outputs from IHostedService and in the Startup of the server has the "correct" ExecutionContext and so is logged to XUnitContext, but anything after that (such as controller calls) do not.

Turns out that there's a boolean switch on the TestServer that's pretty hard to find and that tells whether or not to preserve the ExecutionContext

I think we should document this so nobody else spends a few hours troubleshooting this.

GeeWee avatar Sep 22 '21 13:09 GeeWee

I have added a PR that documents the steps I took to make logging work.

GeeWee avatar Sep 22 '21 13:09 GeeWee