How can I debug Ginkgo tests in VS Code?

4.9k views Asked by At

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!

2

There are 2 answers

5
bighairdave On BEST ANSWER

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.

0
Chetan Kolhe On

Tried out by creating launch.json , but not work for me , I Used bellow code to filter out the test case and used normal debug functionality .

func TestEnd2End(t *testing.T) {
format.MaxLength = 0
RegisterFailHandler(Fail)
suiteConfig, reporterConfig := GinkgoConfiguration()
suiteConfig.LabelFilter = "DEBUG"
suiteConfig.FocusStrings = []string{"sample"}
RunSpecs(t, "End2End Suite", suiteConfig, reporterConfig)}

Note :suiteConfig is used to filter out . Not convenient way but work for me .