I’m working on a Flutter project and set an environment variable for testing. However, during integration tests, the variable is not accessible. Here’s what I did:
Set an environment variable:
export my_key='your_api_key_here'
Verified the environment variable:
echo $my_key
Tried accessing it in the Flutter test with and both of them are not working
const key = String.fromEnvironment("my_key")
final key1 = Platform.environment['my_key']
Checked all environment variables and saw that my_key is not there. The environment is different.
Ran the tests with:
flutter test integration_test/test_feature.dart -d emulator-5554
The environment variable my_key is not accessible during the test. It seems the test environment is isolated and does not inherit my terminal’s environment variables.
How can I ensure my Flutter integration tests access the environment variables I set? Any recommendations to pass environment variables to the Flutter test environment?