What is Alternative of IClassFixture<WebApplicationFactory<Startup>> in .net 6 for IntegrationTests?

Viewed 26

I saw IClassFixture<WebApplicationFactory> in .net core 3 for IntegrationTests, now I want to write an integration test for a project which is .et6, what should I use instead of IClassFixture<WebApplicationFactory> in .net 6 for IntegrationTests ?

Here is what I tried:

public class TicketControllerTests : IClassFixture<WebApplicationFactory<Program>>
{
    private readonly HttpClient _client;
    public TicketControllerTests(WebApplicationFactory<Program> factory)
    {
        _client = factory.CreateDefaultClient();
    }

    [Fact]
    public async Task Get()
    {
        var response = await _client.GetAsync("/Tickets/Test");

        //Assert
        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
    }
}

Here I get this error:

enter image description here

1 Answers

You can use IClassFixture in all versions of .Net.

I think your error comes from Program.cs, put your codes here to help you.

Related