在 ASP.NET Core 集成测试中使用了 WebApplicationFactory ,并且继承 Startup 实现了 TestStartup
public class UploadControllerTests : IClassFixture<UploadWebAppFactory<TestStartup>> { private readonly WebApplicationFactory<TestStartup> _factory; public ImageUploaderControllerTests( UploadWebAppFactory<TestStartup> factory) { _factory = factory; factory.ConfigureLogging(); } //...}
在运行测试时出现了如下的错误:
System.InvalidOperationException : No method 'public static IWebHostBuilder CreateWebHostBuilder(string[] args)' found on 'AutoGeneratedProgram'. Alternatively, WebApplicationFactory`1 can be extended and 'protected virtual IWebHostBuilder CreateWebHostBuilder()' can be overridden to provide your own IWebHostBuilder instance. Stack Trace: at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory`1.CreateWebHostBuilder()
如果不使用 TestStartup ,直接使用 Startup 则没问题,请问如何解决?