godog
godog copied to clipboard
debugging with VSCode
Is it possible to debug a godog scenario using breakpoints with VSCode? I could not find a way to do it, and I wonder if anybody had luck in doing that.
what prevents you from running the code as regular go tests? just open the *_test.go file and press F5. everything should work. You can place regular breakpoints in the implementation.
how about the goland? because there is no main func there, the run is not activated by default. how can I debug godog in goland?
And how would you do this with delve?
I can run a scenario in debug mode in Goland using this run config:

You can add a regular test that invokes godog and then use your IDE capabilities to run/debug tests.
func TestFeatures(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: InitializeScenario,
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}

set environment as GODOG_DEUG= true in the debug configuration and add break points where ever you want
Just add a debug configuration similar to that to your launch.json
:
{
"name": "Debug .feature test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/some_path/main_test.go",
"args": [
"--godog.format",
"pretty",
"-test.run",
"${workspaceFolder}/some_path/some_subpath/your_feature_test.feature"
]
},
You can add a line number where the Scenario:
is defined to debug a single scenario from file, e.g. your_feature_test.feature:102