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:
2
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.I got this error when I was trying to use unconfigured startup (default) in IClassFixture. I think my solution will solve your question indirectly.
I solved this problem by change my program.cs. first, I add this code as ProgramBuilder in my api:
then in my program.cs I add this code:
I used this link it helped me alot:
https://github.com/dotnet/aspnetcore/issues/40361