VSCode - How to cover all files, not just current package?

As per Code coverage for Go integration tests - The Go Programming Language I am able to generate coverage profile for all packages, however, in VSCode, there is only the option to show coverage for current package. How can I make VSCode show coverage for all packages?

Thanks in advance for your reply.

In VS Code, open a new terminal, under PROBLEMS tab, change the filter setting for Show Active Files Only.

In VSCode, to show code coverage for all packages in a Go project, you need to generate a combined coverage report and then use an extension that supports displaying that coverage.

  1. Generate Combined Coverage Report: Run Go tests with coverage for all packages and generate a combined report:
    go test -coverprofile=coverage.out ./…
  2. Use a Coverage Extension: Install a VSCode extension like “Coverage Gutters” or “Go Test Explorer.” These extensions allow you to load a coverage report and visualize it within VSCode.
  3. Load the Coverage Report:
  • With the extension installed, open the coverage report (coverage.out) in VSCode.
  • Activate the coverage display feature (usually by clicking an icon or running a command from the command palette).
  • The coverage data should now be visible across all packages in your project.

With this setup, you should be able to view coverage across multiple packages in your Go project within VSCode.

Ensure that you have the official Go extension for VSCode installed. You can find it in the Extensions view (Ctrl+Shift+X) by searching for “Go” and installing the one provided by “Go Team at Google”.

Open your VSCode settings (File > Preferences > Settings or Ctrl+,) and click on the “Open Settings (JSON)” icon in the top-right corner of the settings window.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.