When I was creating unit tests for a .NET Core lambda, I had to be able to unit test with the Environment.GetEnvironmentVariable(). The best practice would have been to decouple this and have an IEnvironmentService which would be able to get all the values out. This way, you would be able to mock out the IEnvironmentService to retrieve values.
However, as I wasn’t able to do this, due to the limitations of the current project and timelines, I had to use Environment.GetEnvironmentVariable(value) in one of the methods. This caused issues when unit testing as the values are not able to be picked up from the launchSettings.json automatically.
What needs to be done is for a Fixture to be created and used within the unit test class. The Fixture would be responsible for opening up the launchSettings.json file and then adding all the values under the “environmentVariables” node as environmentvariables.
This stackoverflow post has the code sample for it. Remember to set “copy to output directory” as always for the launchSettings.json