首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Visual Studio代码中调试Go测试

在Visual Studio代码中调试Go测试
EN

Stack Overflow用户
提问于 2017-03-29 19:35:59
回答 2查看 20K关注 0票数 27

在我的Windows计算机上,我安装了Visual Studio代码。要手动运行测试,我在控制台的项目文件夹中输入

代码语言:javascript
复制
go test main_test.go

它工作得很完美。

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

为此,我打开launch.json并添加一个配置

代码语言:javascript
复制
  {
        "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后,我有

代码语言:javascript
复制
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

你知道为什么会发生这个错误吗?它在寻找什么可执行文件?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-05 21:50:54

要启动用于测试的调试器,我又为launch.json添加了一个配置

代码语言:javascript
复制
{
    "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
        }       
    ]
}

此外,此配置不支持标签。必须禁用测试文件中的所有标签

代码语言:javascript
复制
// +build unit
...
票数 44
EN

Stack Overflow用户

发布于 2021-11-09 21:18:29

对于该模式,您可以选择auto,它将根据活动编辑器窗口选择debugtest

模式的所有选项为autodebugtestexecreplaycore

生成的launch.json将如下所示:

代码语言:javascript
复制
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch file",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${file}"
        }
    ]
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43092364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档