Debugging GO test function in Visual Studio Code

I want to write test in vscode and run them by hitting F5.

  • To get this to work I had to move to the Run tab

  • Open the configuration file with the cog button

  • Add a configuration

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     {
    "name": "Launch test function",
    "type": "go",
    "request": "launch",
    "mode": "test",
    "program": "${workspaceFolder}",
    "args": [
    "-test.v",
    "-test.run",
    "^TestHTTPServerGetID$",
    ],
    "showLog": false
    }
  • Set a breakpoint and hit F5 at will!

References:

Notes:

  • The "^TestHTTPServerGetID$", part indicates the test. It allows for a regular expression.
  • Ensure to set the subfolder eg. "program": "${workspaceFolder}/subpackge",