2017-03-29 91 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 
... 
相關問題