0
votes

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)?

1

1 Answers

0
votes

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;
    }