1

I have a go program using cobra commands. I can run and debug a command with

{
    "name": "Reporting1",
    "type": "go",
    "request": "launch",
    "mode": "auto",
    "program": "main.go",
    "args":["Reporting1"],
    "console": "integratedTerminal"
},

This will start Reporting1 in debug mode. I have a Reporting_test.go

//go:build unit
// +build unit

package cmd

import (
    "testing"
)

func TestReportingCmd(t *testing.T) {
    t.Parallel()
...

When executing "go test ./cmd/... --short -v -json -tags=unit" It runs all the tests, also the ones from the other commands but I am unable to do it in debugger mode. Is there any launch configuration which will allow me to debug it with VS Code? Thanks Eckard.

I have tried any kind of arguments in lauch.json for "program": "main.go" and "args" but did not got it running.

"program": "Reporting_test.go"
did not work because inside I call the reporting function which is defined via Reproting_generated.go where the reportingCmd is called which is implemented in executeReporting.go It would be OK to just run one test or all the tests at once in debug mode.

eglease
  • 2,445
  • 11
  • 18
  • 28
eckard
  • 11
  • 3
  • You may try to replace ```args``` parameter in launch.json with following: ```"args": ["-test.v", "--", "Reporting1"]``` – vtm11 Aug 21 '23 at 19:26
  • Unfortunatley that did not work for me it is just doing "Executing Main Run command" but neither command itself nor tests are executed – eckard Aug 29 '23 at 19:07
  • How exactly do you try to run the tests? I suggest that you switch to ```Reporting_test.go``` , press ```Ctrl+F5``` (Run without debugging) or ```F5``` (Start debugging). You can have two configurations in ```launch.json``` - one for running tests and one for running ```main```. – vtm11 Aug 30 '23 at 16:54
  • You can refer to this [thread](https://stackoverflow.com/questions/71767280/debugging-go-tests-with-command-line-arguments-in-vscode) for more details. – vtm11 Aug 30 '23 at 16:56

0 Answers0