【发布时间】:2021-07-22 16:59:02
【问题描述】:
我使用 xunit 为 aspnetcore 3.1 应用程序编写了一些集成测试。 测试显示成功,但进程仍在运行。一段时间后,我得到:
进程 dotnet:1234 已完成运行分配给它的测试,但仍在运行。可能的原因是不正确的异步代码或冗长的测试资源处置[...]
这种行为甚至可以通过样板代码显示:
[Fact]
public async Task TestServer()
{
var hostBuilder = new HostBuilder()
.ConfigureWebHost(webHost =>
{
// Add TestServer
webHost.UseTestServer();
webHost.Configure(app => app.Run(async ctx =>
await ctx.Response.WriteAsync("Hello World!")));
});
// Build and start the IHost
var host = await hostBuilder.StartAsync();
}
如果我添加 await host.StopAsync()...
我在 Ubuntu 18.04 机器上。
【问题讨论】:
标签: asp.net-core integration-testing xunit