作者:sprite_77 | 来源:互联网 | 2023-02-08 11:08
在我的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
任何想法为什么会出现这个错误以及它正在寻找什么可执行文件?
1> Vitalii..:
要启动测试调试器,我为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",
"type": "go",
"request": "launch",
"mode": "test",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/ordering/service_test.go",
"env": {},
"args": [],
"showLog": true
}
]
}
需要手动更改文件路径以调试另一个测试
"program": "${workspaceRoot}/ordering/service_test.go",
此配置也不支持标签.必须禁用测试文件中的所有标记
// +build unit
...