I am creating some tests in Flutter, but I need to set an environment variable before running the tests. Is there a way to set an environment variable when running the app from these "Run | Debug" buttons?
With the new update to the Dart SDK it is possible: https://dartcode.org/releases/v3-11/
[...] For example, to add CodeLens for a launch config that sets a RELEASE_MODE=true
environment variable to tests in test/integration_tests
:
{
"name": "Current File (release mode)",
"type": "dart",
"request": "launch",
"codeLens": {
// Types of CodeLens to inject
"for": [ "run-test", "run-test-file", "debug-test", "debug-test-file" ],
// Restrict to certain folders
"path": "test/integration_tests",
// Text for CodeLens link (${debugType} will be replaced with "run" or "debug")
"title": "${debugType} (release)"
},
"env": { "RELEASE_MODE": true }
}
This will insert additional CodeLens links into tests, groups and main functions: