Is it possible to run a single Go test in VS Code with a launch.json configuration?
Here's my OS and Go version
Windows 11
Delve Debugger Version: 1.24.0
go version go1.23.4 windows/amd64
Right now, the closest thing I have is running all tests in a file with this configuration:
// Attempt at running a single Go test
{
"name": "Go run single test",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${file}",
"args": [
"^TestDoThing"
],
}
I saw someone add the test name to the args in this question, but it didn't affect my results. All the tests in the file still run. Running a single test with a launch.json configuration is more of a convivence than a requirement for me. But I couldn't find any other questions about it or documentation/articles, so I thought it was worth asking about.
So in principle i would say you can just put a breakpoint directly in test case and run it from GUI by clicking debug test
above test case name. However you can try the following:
{
"name": "run-concrete-test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/path/to/your/test-file-dir",
"args": [
"-test.run",
"^TestDoThing"
],
"showLog": true
}