I'm using a .NET Nunit project and trying to create a fixture for my integration tests using WebApplicationFactory class
When I run tests I get the exception
System.InvalidOperationException : The server has not been started or no web application was configured.
But, if debug I don't get any error and the tests run without problems. I literally copy pasted a few different good implementations I found online, and also removed every tests configuration or service replacement, and I still get the error.
This is my configuration
public class Initializer
{
protected WebApplicationFactory<Program> application { get; set; }
protected HttpClient client { get; set; }
protected IServiceProvider _serviceProvider;
[SetUp]
public void RunBeforeAnyTests()
{
application = new WebApplicationFactory<Program>().WithWebHostBuilder(conf =>
{
conf.UseEnvironment("Test");
});
client = application.Server.CreateClient();
_serviceProvider = application.Services;
}
}
I can't investigate because in debug mode I don't have the problem.. I'm stuck on this, anyone can help me?