Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug Ginkgo tests in VS Code?

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!

like image 376
bighairdave Avatar asked Feb 09 '21 09:02

bighairdave


People also ask

How do you debug a ginkgo test?

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.

How do I debug a test in Vscode?

Once you have your launch configuration set, start your debug session with F5. Alternatively, you can run your configuration through the Command Palette (Ctrl+Shift+P) by filtering on Debug: Select and Start Debugging or typing 'debug ' and selecting the configuration you want to debug.

How do I run a code in debug mode?

If you use VS Code to run your Go code and have the official Go extension installed on the editor, you can debug your code by pressing F5 or Run and Debug on your computer.


Video Answer


1 Answers

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.

like image 51
bighairdave Avatar answered Oct 16 '22 09:10

bighairdave