【问题标题】:set an environment variable when running test from run button in VSCODE从 VSCODE 中的运行按钮运行测试时设置环境变量
【发布时间】:2020-07-27 05:46:54
【问题描述】:

我正在 Flutter 中创建一些测试,但我需要在运行测试之前设置一个环境变量。从这些“运行|调试”按钮运行应用程序时,有没有办法设置环境变量?

【问题讨论】:

    标签: flutter testing visual-studio-code codelens


    【解决方案1】:

    随着 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 链接插入到测试、组和主要功能中:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 2019-07-28
      • 2022-11-20
      • 2012-06-20
      • 2011-02-14
      相关资源
      最近更新 更多