You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x/tools/gopls: support equivalent of go.generateTestsFlags -template in default test generator #81065
The migration from gotests to gopls is now done. Gopls expose the same functionality through source code action.
I argue that the inability to use templates in the gopls version of test generation means it does not expose the same functionality.
For example, while usage of such libraries is controversial, testify is one of the most widely imported packages in the open source Go ecosystem. Being unable to generate unit test templates for projects that use it is a meaningful regression in capabilities.
Yes, the "legacy" generator is still available for now, but calling it legacy gives the impression that the intent is to remove it some time soon.
Additionally:
If the setting is deprecated, it should be marked as such. Right now there's no indication that it is a legacy setting that's presumably on its way out, nor that it won't work in the default tooling.
Since the command name hasn't changed, it's quite confusing at first for someone that had it set already that the setting no longer works. This appears as a bug. A notification if the new test generation is invoked that this legacy setting is being ignored might be appropriate (with a "don't show again" option, naturally)
Describe the solution you'd like
I'd like to have the supported test generation support templates, or at least widely used test helper packages, like gotests supports.
Describe alternatives you've considered
Manually editing the generated code every time is possible but tedious
While, we (the Go team) do not endorse the use of "testify", but we think it is a reasonable ask to make the gopls source code action "add test for Func" configurable by accepting a template file or template dir like gopls does. So the user can write their own "test func template" and gopls will generate the test based on the user's preference.
This would mean, users like you, will have to write a template files some where and tell gopls where they are.
Before such feature is implemented, we will keep the "legacy" around.
changed the title [-]Support equivalent of go.generateTestsFlags -template in default test generator[/-][+]x/tools/gopls: Support equivalent of go.generateTestsFlags -template in default test generator[/+]on Aug 24, 2026
changed the title [-]x/tools/gopls: Support equivalent of go.generateTestsFlags -template in default test generator[/-][+]x/tools/gopls: support equivalent of go.generateTestsFlags -template in default test generator[/+]on Aug 24, 2026
Activity
h9jiang commentedon Mar 26, 2026
While, we (the Go team) do not endorse the use of "testify", but we think it is a reasonable ask to make the gopls source code action "add test for Func" configurable by accepting a template file or template dir like gopls does. So the user can write their own "test func template" and gopls will generate the test based on the user's preference.
This would mean, users like you, will have to write a template files some where and tell gopls where they are.
Before such feature is implemented, we will keep the "legacy" around.
fastcat commentedon Mar 26, 2026
Fair 👍
[-]Support equivalent of go.generateTestsFlags -template in default test generator[/-][+]x/tools/gopls: Support equivalent of go.generateTestsFlags -template in default test generator[/+][-]x/tools/gopls: Support equivalent of go.generateTestsFlags -template in default test generator[/-][+]x/tools/gopls: support equivalent of go.generateTestsFlags -template in default test generator[/+]