Skip to content
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

VSCode gopls testify/suite : When tests within a test suite are split across separate files, how to display Run and Debug Test Links in VSCode? #1130

Closed
dcs3spp opened this issue Jan 28, 2021 · 2 comments

Comments

@dcs3spp
Copy link

dcs3spp commented Jan 28, 2021

Hi I am using gopls in VSCode and have the following issue/question detailed below. Hopefully, this is the correct place to report, if not please direct to correct place to submit query/issue.

What version of Go are you using (go version)?

$ go version go1.15.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
O111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/really?/Library/Caches/go-build"
GOENV="/Users/really?/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/really?/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/really?/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/really?/Development/Projects/Go/form3/accountapi-client/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/h5/k56b8xzj3cbbx4b3_rnmq2_00000gn/T/go-build062526535=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have implemented some integration tests using testify/suite. The tests in the test suite are split across files organised by feature as opposed to bunching them all together in one large file. I can confirm that the all tests in the suite run through the terminal using go test command.

However, within VSCode the links for running and debugging each test are not displayed across all files that contain tests in the test suite:

  1. Declare the test suite struct and any test hooks (before, after etc.) in a separate source file, e.g.testsuite.go.
  2. Create separate files for testing each feature: feature_1_tests.go, feature_2_tests.go etc. These contain the tests for the test suite organised by feature, e.g.:

feature_1_test.go

func (suite *IntegrationTestSuite) TestFeat1_MyTest {}
...

feature_2_test.go

func (suite *IntegrationTestSuite) TestFeat2_SeparateTest {}
...
  1. Declare function in feature_1_tests.go for running the test suite:
// TestIntegrationTestSuite for 'go test' to run this suite, we need to create
// a normal test function and pass our suite to suite.Run
func TestIntegrationTestSuite(t *testing.T) {
	suite.Run(t, new(IntegrationTestSuite))
}

Links for running and debugging the test are displayed in VSCode within go_feat1_integration_test.go. However, there are no links for creating and debugging tests displayed for the tests in file feature_2_test.go.

What did you expect to see?

It should be possible to see links for running and debugging tests across all files that contain tests for a test suite in VSCode. How to achieve this?

What did you see instead?

Run and debug links are only shown on the test file that contains the function to start the test suite:

// In order for 'go test' to run this suite, we need to create
// a normal test function and pass our suite to suite.Run
func TestIntegrationTestSuite(t *testing.T) {
	suite.Run(t, new(IntegrationTestSuite))
}
@stamblerre stamblerre transferred this issue from golang/go Jan 28, 2021
@hyangah
Copy link
Contributor

hyangah commented Jan 29, 2021

The test code lenses depend on vscode's DocumentSymbolProvider implementation (Code). Unfortunately, DocumentSymbolProvider API is designed around a single document, so this cannot handle your use case.

When we eventually implement PackageSymbolProvider, that may be possible.

@gopherbot gopherbot added this to the Untriaged milestone Apr 8, 2021
@stamblerre stamblerre modified the milestones: Untriaged, Backlog Apr 9, 2021
nirhaas added a commit to nirhaas/vscode-go that referenced this issue Jul 2, 2022
When evaluating whether a symbol is a document or not, check if testify was imported by any file of the directory (which is the go package).

Fixes golang#1130
nirhaas added a commit to nirhaas/vscode-go that referenced this issue Jul 2, 2022
When evaluating whether a symbol is a document or not, check if testify was imported by any file of the directory (which is the go package).

Fixes golang#1130
@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/415894 mentions this issue: add support for multi-file test suite

nirhaas added a commit to nirhaas/vscode-go that referenced this issue Jul 12, 2022
When evaluating whether a symbol is a document or not, check if testify was imported by any file of the directory (which is the go package).

Fixes golang#1130
@hyangah hyangah modified the milestones: vscode-go/unplanned, v0.35.0 Jul 12, 2022
@golang golang locked and limited conversation to collaborators Jul 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants