我尝试运行集成测试,但是遇到了这个错误:
System.InvalidOperationException: 入口点退出而没有构建 IHost。 at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.CreateHost() at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass10_0.b__0(String[] args) at Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.Build() at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory
1.CreateHost(IHostBuilder builder) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory
1.ConfigureHostBuilder(IHostBuilder hostBuilder) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.EnsureServer() at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory
1.CreateDefaultClient(DelegatingHandler[] handlers) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory
1.CreateClient(WebApplicationFactoryClientOptions options) at Ptco.System.IntegrationTests.Infrastructure.IntegrationTestsWebFactory.CreteManagedClient() in C:\Users\nemes\Documents\GitHub\ptco.app\System\Ptco.System.IntegrationTests\Infrastructure\IntegrationTestsWebFactory.cs:line 249
第 249 行是:
private HttpClient CreteManagedClient() =>
CreateClient(new WebApplicationFactoryClientOptions
{
BaseAddress = new Uri(_configuration.GetValue<string>("IntegrationServerBaseUri"))
});
这被称为这样
public IntegrationTestsWebFactory()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
_configurationPath = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json");
_configuration = BuildConfiguration();
ManagedHttpClient = CreteManagedClient();
}
我该如何解决这个错误?