Yesterday I blogged about how to get started with integration testing in ASP.NET Core.
If you are using this technique, you might get a few issues while migrating from .NET Core 2.2 to .NET Core 3.0 or 3.1.
It could be that you get the following error message:
No method 'public static IHostBuilder CreateHostBuilder(string[] args)' or 'public static IWebHostBuilder CreateWebHostBuilder(string[] args)' found on 'AutoGeneratedProgram'. Alternatively, WebApplicationFactory`1 can be extended and 'CreateHostBuilder' or 'CreateWebHostBuilder' can be overridden to provide your own instance.
You should use the
CreateHostBuilder()
method. It is still possible to access the WebHostBuilder
through the ConfigureWebHostDefault()
method:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class SelfHostedApi : WebApplicationFactory<Api.Startup> | |
{ | |
protected override IHostBuilder CreateHostBuilder() | |
{ | |
return Host.CreateDefaultBuilder().ConfigureWebHostDefaults(builder => | |
builder.UseStartup<Api.Startup>()); | |
} | |
protected override void ConfigureWebHost(IWebHostBuilder builder) | |
{ | |
builder.ConfigureServices(services => | |
{ | |
}); | |
} | |
} |