golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.84k stars 735 forks source link

Support to run single test case in table driven unit test #3091

Closed mingqishao closed 8 months ago

mingqishao commented 8 months ago

Is your feature request related to a problem? Please describe. We usually use table driven in unit test. Here is a simple example. Our problem is I can't run single test case. If one test failed and I want to run it again. I have to comment out all other test case, then run the whole xxx_Test() function.

Describe the solution you'd like Support run the single test case in table driven unit test like subtest today.

jim-minter commented 8 months ago

Adding more detail. The screenshot below shows a "traditional" test approach using t.Run() for sub-tests, and an equivalent table-driven approach. In the traditional approach, individual sub-tests can be executed directly from vscode by clicking the "run test" label that appears. It would be amazing if the same thing were possible in the table driven approach, i.e. if vscode could recognise that each entry in the slice being ranged represents a sub-test, and provided a separate "run test" label for it by the struct definition.

Clearly it wouldn't be possible to support arbitrarily complex non-constant arguments for t.Run, or arbitrarily complex table-driven test implementations, but I'd have thought that it should be possible to support tests with a single t.Run call, where the name references a struct field in a slice which is being ranged? Being able to do this would be incredibly useful!

Screenshot_2023-12-13_11-22-31

jim-minter commented 8 months ago

I think this is a duplicate of #2445.