![](/img/trans.png)
[英]Using IdentityServer4 with WebApplicationFactory Integration Tests
[英]"No app configured" error while using WebApplicationFactory for running integration tests
我正在為我的應用程序編寫集成測試,它使用 .net5 我已經使用 WebApplicationFactory 和 IHostBuilder 來設置環境。
自定義夾具 ->
public class TestFixture<T> : WebApplicationFactory<Program>
{
protected override IHostBuilder CreateHostBuilder()
{
var builder = Host.CreateDefaultBuilder();
builder.ConfigureAppConfiguration((hostingContext, config) =>
{
var env = hostingContext.HostingEnvironment;
config.SetBasePath(env.ContentRootPath);
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
config.AddEnvironmentVariables();
})
.ConfigureServices((hostContext, services) => { services.Configure(hostContext); });
return builder;
}
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureTestServices((services) =>
{
services.RemoveAll(typeof(IHostedService));
});
}
}
services.Configure(hostContext) 調用注冊工作流的 UnityContainer( https://github.com/danielgerlag/workflow-core )。
錯誤描述 -> 未配置應用程序。 請通過 IWebHostBuilder.UseStartup、IWebHostBuilder.Configure 指定應用程序,或通過 Web 主機配置中的 StartupAssemblyKey 指定啟動程序集
添加此代碼: .ConfigureWebHostDefaults(b => b.Configure(app => {}));
在.ConfigureServices
調用之后
您正在使用不運行網絡主機的 Worker Service。 但是,WebApplicationFactory 仍然需要一個,因此創建一個空的 Web 應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.