14

I'm evaluating ginkgo at the moment - I very much like the BDD style.

However I'm unable at the moment to get the VS Code debugger to work with the framework. The official VS-Code extension provides test-by-test debugging for native go tests using CodeLens. With other languages and frameworks (eg Typescript/Mocha), I've been able to debug individual test files by setting up launch.json appropriately, but have been unable to find suitable examples for go.

Does anybody have any examples of any launch.json setups for debugging ginkgo tests (or go code invoked from any other framework)?

Thanks!

bighairdave
  • 592
  • 5
  • 19

1 Answers1

15

After a bit of playing around I found a way forward which perhaps should have been obvious. In case it isn't I'll leave the question and this answer here:

For a package foo, a foo_suite_test.go file is generated by the gingko bootstrap command. This contains a top-level test called TestFoo which runs the rest of the tests within the package.

This does have a CodeLens run test | debug test section above it which you can use to debug the entire suite.

CodeLens screenshot

It's not quite as convenient as the individual CodeLens entries which appear over each native go test, but it's easy enough to isolate specific tests to run using the Gingko F prefix.

bighairdave
  • 592
  • 5
  • 19
  • Thanks, you just made this so much easier, I've been banging my head against this for a while :) – Slashy Feb 16 '22 at 16:40
  • How can I invoke this from the command palette, so I can program a macro key for it? – TheDiveO Mar 08 '22 at 10:33
  • @TheDiveO not sure you can directly invoke from command pallette but you can get the `go test` command by clicking on 'run test' and looking at the output pane. Then set up a debug task for it in `launch.json`. Then you'll be able to invoke directly from the debug menu. – bighairdave Mar 09 '22 at 11:16
  • that's an idea, but this begs the question how to launch the correct task unambiguously... – TheDiveO Mar 09 '22 at 12:24
  • Perhaps it would be worth raising a specific question on this? – bighairdave Mar 09 '22 at 12:57