簡體   English   中英

使用 vscode 在 golang 中調試測試的問題

[英]Issues with debugging tests in golang with vscode

我正在使用一些全局變量在 VSCode 上運行 Golang 測試,這些變量在到達測試函數之前被初始化。

我的程序中的全局變量從 runline 參數中獲取它們的值,這些參數在 launch.json 文件 (os.Args) 中指定。

出於某種原因,當我運行測試時,我的參數與 launch.json 文件中指定的參數不同。

這些是我的啟動文件的內容:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch file",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${file}",
            "args": [".", "from", "to", "csv", "hl7"]
        }
    ]
}

這些是我不斷得到的不同價值觀:

os.Args[0] = //path to the __debug_bin.exe
os.Args[1] = "-test.run"
os.Args[2] = "^TestInit$"

在我的 launch.json 文件中,我總共有 6 個參數,這導致我在嘗試運行測試時出現越界錯誤。

所以我的問題是如何更改它以便使用我在啟動文件中指定的參數運行測試?

codelens 目前不支持此功能,請在此處查看codelens:在運行測試中使用選定的 launch.json 配置的方法 | 調試

但你可以這樣做

  1. setup "go.testFlags": ["-v", "-args", "from", "to", "csv", "hl7"]在用戶設置(文件路徑)"Code\User\settings.json "

你可以像這樣檢查

t.Log(os.Args[3])
t.Log(os.Args[4])

……

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM