[从VSCODE中的运行按钮运行测试时设置环境变量

问题描述 投票:0回答:1

我正在Flutter中创建一些测试,但是在运行测试之前,我需要设置一个环境变量。通过这些“运行|调试”按钮运行应用程序时,是否可以设置环境变量?

enter image description here

flutter testing visual-studio-code codelens
1个回答
0
投票

通过Dart SDK的新更新,可以:https://dartcode.org/releases/v3-11/

[...]例如,为启动配置添加CodeLens,该启动配置将RELEASE_MODE=true环境变量设置为在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 }
}

这会将其他CodeLens链接插入测试,组和主要功能:

© www.soinside.com 2019 - 2024. All rights reserved.