2017-03-29 92 views
2

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

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 

任何想法,为什么出现这种错误,什么可执行程序,它在寻找?

+1

尝试指定与可执行文件中配置“程序”财产“$ {} workspaceRoot /main_test.go” – Bob

+0

就是这样,谢谢! – Vitalii

回答

3

要测试启动调试器我添加了一个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 
... 
相关问题