在我的Windows计算机上,我安装了Visual Studio代码。要手动运行测试,我在控制台的项目文件夹中输入
go test main_test.go它工作得很完美。

但是我有一种情况,我需要调试我的测试来了解发生了什么。
为此,我打开launch.json并添加一个配置
{
"name": "Tests",
"type": "go",
"request": "launch",
"mode": "test",
"remotePath": "",
"port": 2346,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [
"main_test.go"
],
"showLog": true
}在我按下F5后,我有
2017/03/29 13:28:11 server.go:73: Using API v1
2017/03/29 13:28:11 debugger.go:68: launching process with args: [./debug.test main_test.go main_go]
not an executable file
Process exiting with code: 1你知道为什么会发生这个错误吗?它在寻找什么可执行文件?
发布于 2017-04-05 21:50:54
要启动用于测试的调试器,我又为launch.json添加了一个配置
{
"version": "0.2.0",
"configurations": [
{
"name": "Code",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"showLog": true
},
{
"name": "Test Current File",
"type": "go",
"request": "launch",
"mode": "test",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${file}",
"env": {},
"args": [],
"showLog": true
}
]
}此外,此配置不支持标签。必须禁用测试文件中的所有标签
// +build unit
...发布于 2021-11-09 21:18:29
对于该模式,您可以选择auto,它将根据活动编辑器窗口选择debug或test。
模式的所有选项为auto、debug、test、exec、replay、core。
生成的launch.json将如下所示:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${file}"
}
]
}https://stackoverflow.com/questions/43092364
复制相似问题