Skip to content

x/tools/gopls: support equivalent of go.generateTestsFlags -template in default test generator #81065

Description

@fastcat

Is your feature request related to a problem? Please describe.

Since golang/vscode-go#1594, the go.generateTestsFlags setting is no longer honored by the default command.

@h9jiang claimed in the last comment there

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

Additional context

N/A

Activity

  1. h9jiang commented on Mar 26, 2026

    @h9jiang
    Member

    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.

  2. fastcat commented on Mar 26, 2026

    @fastcat
    Author

    Fair 👍

  3. transferred this issue fromgolang/vscode-goon Aug 24, 2026
  4. 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
  5. 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
  6. self-assigned this
    on Aug 24, 2026
  7. added
    goplsIssues related to the Go language server, gopls.
    on Aug 24, 2026
  8. added theissue type on Aug 24, 2026
  9. added this to the gopls/backlog milestone on Aug 24, 2026
  10. added
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    on Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions