gpt4 book ai didi

unit-testing - 在 Visual Studio Code 中调试 Go 测试

转载 作者:IT王子 更新时间:2023-10-29 01:24:25 26 4
gpt4 key购买 nike

在我的 Windows 机器上,我安装了 Visual Studio Code。要手动运行测试,我进入控制台到项目文件夹并输入

go test main_test.go

它完美地工作。

enter image description here

但我有一种情况需要调试我的测试以了解发生了什么。

为此,我打开 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

知道为什么会出现此错误以及它正在寻找什么可执行文件吗?

最佳答案

为了启动调试器进行测试,我为 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
...

关于unit-testing - 在 Visual Studio Code 中调试 Go 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43092364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com