I have been using WebApplicationFactory for integration testing in .NET 5, .NET Core 3.1 and .NET Core 2.1 . It is all working fine for me.
I just create my project with:
dotnet new webapi
and then I see a web api project with a Startup class.
Then I create an instance of the factory class:
private readonly WebApplicationFactory<Startup> factory = new WebApplicationFactory<Startup>();
The WebApplicationFactory class is something I really like. It makes it easy to write integration tests. I like it a lot. The Microsoft docs also refer to it for .NET 6.
However, how do I, when using .NET 6, make sure my code compiles?
The mentioned command-line statement:
dotnet new webapi
results in a nicely working project but (when having the .NET 6 SDK installed) without a Startup class...... Now my tests do not compile for just one reason: the Startup class does not exist.
How to fix this? I find it hard to imagine that I cannot write integration tests anymore because WebApplicationFactory<Startup> does not compile anymore. But right now, this is the reality I need to deal with. How can I solve the problem? I look forward to being able to use the WebApplicationFactory class and continue writing integration tests. But how?