[英]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 配置的方法 | 调试
但你可以这样做
"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.