godog icon indicating copy to clipboard operation
godog copied to clipboard

debugging with VSCode

Open mdelapenya opened this issue 4 years ago • 7 comments

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.

mdelapenya avatar Jun 30 '20 15:06 mdelapenya

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.

MetalBlueberry avatar Jul 13 '20 17:07 MetalBlueberry

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?

yuseferi avatar Nov 04 '20 14:11 yuseferi

And how would you do this with delve?

paschelino avatar Apr 15 '21 16:04 paschelino

I can run a scenario in debug mode in Goland using this run config:

image

stevecager avatar May 13 '22 12:05 stevecager

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")
  }
}
image

vearutop avatar May 20 '22 12:05 vearutop

set environment as GODOG_DEUG= true in the debug configuration and add break points where ever you want

waytocypress avatar Jul 14 '22 16:07 waytocypress

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

witgaw avatar Nov 24 '22 15:11 witgaw