Running tests in a module

As you might be aware, modules allows go packages outside GOPATH. I'm working on a project which uses Go 1.11 module, and is outside GOPATH. I can't run tests in GoLand 2019.1 via run test icon in editor gutter without additional configuration. Here is a simple example:

// filetotest.go
package main
func Function() {}

// filetotest_test.go
package main
import "testing"
func TestFunction(t *testing.T) {
Function()
}

Inside GOPATH, I can run the test easily. But moving the project outside GOPATH and after "go mod init moduleName", clicking the run test icon will output "./filetotest_test.go:6:2: undefined: Function". One way to fix this is to add all necessary files to the configuration, but I can't do this for each new test I run.

I'm hoping there is an easy way to run individual tests in modules. Please let me know how to run tests via editor. Thank you.

2 comments
Comment actions Permalink
Official comment

Could you please check that integration is enabled for your project under Settings | Go | Go Modules (vgo)?

Comment actions Permalink

Thanks, it works after enabling Go Modules integration. I was confused when I created the project because I wasn't sure what "vgo" was, though I now understand it's the prototype to modules.

0

Please sign in to leave a comment.