在 ASP.NET Core 集成測試中使用了 WebApplicationFactory ,并且繼承 Startup 實(shí)現(xiàn)了 TestStartuppublic class UploadControllerTests : IClassFixture<UploadWebAppFactory<TestStartup>>
{ private readonly WebApplicationFactory<TestStartup> _factory; public ImageUploaderControllerTests(
UploadWebAppFactory<TestStartup> factory) {
_factory = factory;
factory.ConfigureLogging();
} //...}在運(yùn)行測試時(shí)出現(xiàn)了如下的錯(cuò)誤: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 則沒問題,請(qǐng)問如何解決?
- 1 回答
- 0 關(guān)注
- 665 瀏覽
添加回答
舉報(bào)
0/150
提交
取消