简体   繁体   中英

ASP. Net Core integration tests

I read a documentation about integration tests in ASP .Net Core from https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.1

Does ConfigureWebHost method from CustomWebApplicationFactory should be executed once for all tests or for each test?

And why, when I use web host (not generic host), this method (with ConfigureTestService) is executed after WithWebHostBuilder (with ConfigureTestService)?

As you can see in the article the best way is to have a registered service and inject it via constructor to every Test class.

public class BasicTests : IClassFixture<WebApplicationFactory<RazorPagesProject.Startup>>
{
    private readonly WebApplicationFactory<RazorPagesProject.Startup> _factory;

    public BasicTests(WebApplicationFactory<RazorPagesProject.Startup> factory)
    {
        _factory = factory;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM