-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debug: ability to generate launch configs for debugging particular tests #1845
Comments
Follow up... What I'm asking for seems to already exist. I didn't see it the first time I tried to do it. But after already having a launch.json file, and trying to add a second launch config, I see it as one of the Go options presented to me: So maybe the solution here is to change the options presented to the user as they create their first launch config. |
@mattwelke Thank you for detailed report. That said, these configurations will not apply There is also the option of using |
@mattwelke Do you mean to run or debug multiple tests? There are already shortcuts to "run package tests" and "run file tests" at the top of your test file. Usually once you identify a bad test, you benefit from debugging just that test, so I am not sure how necessary the equivalent "debug package tests" shortcut would be. You can also tweak "Launch test function" configuration to run over all functions (none specified in the args) and the program argument to use a specific test file or package. Do you think that's too hard of a leap, and we need all flavors ("Launch test file", "Launch test package") separately? |
@polinasok Thanks for the reply. It's been a while since I created this so I want to review it, gather my thoughts, and respond back soon. |
@mattwelke Thank you. Sounds good.
|
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Is your feature request related to a problem? Please describe.
I like to debug tests by clicking on the "debug test" text:
Debugging tests as opposed to just running them (with "run test") is useful because I can set breakpoints to observe the state of the program at arbitrary points during the test, or allow the program to continue one line at a time during a test to see what causes a panic.
The problem I encountered today is that I needed to run a test, while debugging, and I needed environment variables set for that particular test. It's more of an integration test, so it involves interacting with GCP APIs, and I needed to be able to set the GOOGLE_APPLICATION_CREDENTIALS environment variable that the test requires.
My current understanding of debugging in VS Code is that if you want to set up things like environment variables to be used by the program, you need to use a launch config. I do that by clicking on "create a launch.json file" from a Go project:
Then, I'm presented with the types of Go launch configs that VS Code can generate for me:
The problem is that none of these will work for my use case. I need to run a specific test, not run an entire Go package. I could read into how the go CLI tool works to learn for myself what I can set up, but it'd be convenient if VS Code could help me with this and keep me in the zone.
Describe the solution you'd like
I would like an easy way to generate launch configs for running particular tests in a Go project. As a bonus, it'd be nice if we could choose launch configs for all types of testing one usually does in Go (all tests, all tests in a package, all tests in a file, or just one particular test). It would be nice if I could create the launch config by clicking on some UI element near the "debug test" UI element, in which case the launch config would automatically include the right go command to run just that test.
Alternatively, if launch configs aren't the best way to solve my use case (including environment variables while running a test), something else could be implemented that would allow one to set environment variables for a test easily. Then, they could run them by clicking "debug test" or "run test" without having to set up a launch config.
Describe alternatives you've considered
Starting from the "Go: Launch Package" launch config template, consulting the go CLI tool documentation to learn how to use it to run just one test, and then adding my environment variable config to that launch config. Repeating this step for every test I need to manually debug with environment variables.
The text was updated successfully, but these errors were encountered: