Here's the launchSettings.json file for the test project:
{
"profiles": {
"test": {
"commandName": "test",
"environmentVariables": {
"Hosting:Environment": "Development"
}
}
}
}
The test project has a dependency on the server project, and initializes the tests using the server project's Startup
class directly like so:
Server = new TestServer(TestServer.CreateBuilder().UseStartup<Startup>());
Client = Server.CreateClient();
Yet for some reason, when I enter the Startup.Configure
method in the debugger, env.EnvironmentName
is Production. Where am I supposed to set the environment name for the test .xproj?
On a related note, should I have a local test version of the Startup
class in the test project? The docs seem to suggest otherwise... And where will the appsettings come from? They don't show the test project as having a copy of the appsettings locally, but I'm pretty sure the Startup
class (whether reused or local) will need it. Please advise.
You can use the UseEnvironment method.
Server = new TestServer(TestServer.CreateBuilder().UseEnvironment("Testing").UseStartup<Startup>());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With